Having read a post yesterday, I realized I did not know much about the origin of exceptions. Is it an OOP related concept only? I tend to think it is, but again there are database exceptions.
Are exceptions an OOP concept?
programming languages;exceptions
Exceptions are not an OOP concept. But they are not completely unrelated either in one little tiny point.As other answers have shown: The concept of exceptions has made it in several non-OOP languages. Nothing in that concept requires something from OOP.But any if not all OOP languages which takes OOP seriously require exceptions because the other methods of error-handling fail at one specific point: The constructor. One of the points of OOP is that an object shall encapsulate and manage its internal state completely and consistently. This also means that in pure OOP you need a concept to create a new object with a conistent state atomically - everything from memory allocation (if required) to the initialisation to a meaningful state (i.e. simple zeroing the memory is not enough) must be done in one expression. Hence a constructor is required:Foo myFoo = Foo(foo, bar, 42);But this means that the constructor can also fail due to some error. How to propagate the error information out from the constructor without exceptions?Return value? Fails since in some languages new could return only null but not any meaningfull information. In other languages (e.g. C++) myFoo is not a pointer. You could not check it against null. Also you cannot ask myFoo about the error - it is not initialized and therefore does not exist in OOP thinking.Global error flag? So much about encapsulating state and then some global variable? Go to h... ;-)A mixture? In no way better.?So exceptions are a more fundamental concept than OOP but OOP builds upon them in a natural way. 