Question:
What is the purpose of "Error/Exception Handling"?
lyderslim
2009-06-16 06:41:06 UTC
I interviewed for an Oracle Developer position and two DBA's both asked me this question. I really didn't know how to answer it or what they were looking for in an answer. I thought, "well jees. If an error occurs in my code, I need to 'handle' it so the program doesn't just 'crash'".

I use exception blocks in all of my code and I usually log an error in my log table, rollback changes if I need to, pass the error back to the calling program, and notify someone that this did not succeed.

I see Wiki says "Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions - special conditions that change the normal flow of execution."

What do you think a DBA wants to hear from a prospective developer about error handling? Am I suppose to be closing cursors or wrapping up some sort of memory leaks somehow?
Three answers:
2009-06-16 07:00:23 UTC
It is not to just ensure your application doesn't crashes, but that is part of it. You use exception handling to control your application. There are times when you will do things and not guaranteed it will succeed. For example, connected to a database and the network is down or the user gave you the wrong username/password. Rather than just erroring out, you can respond back to the user and try again, or some other controlled reaction. Not all exceptions reflect fatal errors.



The other use is similar, but it is a way to unwind your code when you get to the bowels and find out things just don't work. You can raise an exception in your code, pop back to the controller loop, report the error in the system log and to the user and decide what to do next.



Certainly the cleanup you mention is one of the key things you should do as part of the recovery for the exception.
2017-01-11 20:05:09 UTC
Purpose Of Exception Handling
La Verdad
2009-06-16 06:53:54 UTC
i Do not know for sure, but I would assume it is just so that your program will not crash or mess up when an error occurs, so you just "handle" it


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...