Why when I'm casting a spell and I get hit right when I start casting that it doesn't get interrupted till the spell is "done" casting?

Is this a glitch or something because it doesn't make much sense to me that it interrupts at the end and not as soon as I get hit.