Why Are Errors Named ‘Exception’ Instead of ‘Error’ in Programming Languages?

exceptionsprogramming-languagesterminology

I've been thinking about that for quite a while actually. I am not a native English speaker myself but still, I have years of programming experience and I always asked myself this. Why is it named as Exception but not Error since they are errors?

It could be PageNotFoundError instead of PageNotFoundException!

Best Answer

They don't need to be errors at all. The fact that the page is not there may be just an interesting fact rather than an actual error. They seem to get used as errors almost all the time, I admit. But sometimes they're used to break out of loops, or let you know that a string is not a valid number. They can be used to hold and return vast amounts of useful data--as part of a fairly normal return. (Some languages are a bit slow with their exceptions, in that case throwing them frequently is a bad idea.) In theory anyway, an exception merely means "don't do a normal return, go up the call stack until you find someone interested in this."

Even a null pointer exception might not mean much to you. You call someone else's code, and then catch a null pointer exception because you know it's apt to blow up, print a message saying whose fault it is, and carry on and get your job done.