Before I get into what error handling is all about in an OOP (object oriented programming language), Let me first talk about what an actual error code is and how they show up on your code. Well your a perfect programmer you don’t need any “handling” of your marvelous code your logic is solid and you know exactly how your program is going to react when it gets executed. Sadly enough I have to be the one to tell you but you are WRONG! This is one of the issues many programming languages have had over the years. That they leave all this error handling task to the class designers or who ever wants to deal with them. Here is where exceptions come in, think about exceptions like something that happens when your code does not know how to react to something new, welcome to the world of exception handling. The simple break down of this goes like this when the code “throws” and exception it needs to be “caught”, get it he threw it some one has to catch it. The one that is catching the error is called the exceptions handler this code runs separately from your main code meaning that exceptions are not ignored.
You must be asking your self well doesn’t a return statement do the same thing? No it does not, see the main difference like I said before the return statement is part of the code, the exception handler is completely separate from the original code. So besides being this super awesome code we can write to make our programs much more stable, they also help on recovering from bad situations, and ways to deal with them properly giving you a more robust program.
One last note to remember that a lot of new people think of exception handling as an object oriented feature, just because I gave an example of an object getting thrown as exception does not mean that its a oop feature, many procedural languages allow for exceptions.
I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More