Trapping and handling of runtime errors is one of the most crucial taska ahead of any programmer. AS A DEVELOPER, YOU SOMETIMES SEEM TO SPEND MORE TIME CHECKING FOR ERRORS AND HANDLING THEM THEN YOU DO ON THE CORE LOGIC OF THE ACTUAL PROGRAM.
yes you can use Exception for tracing bugs and point in code where problem is , before I know formal debugging via Eclipse I used to do this, I just throw Exception from code catch it and print stack trace this way I ensure that my control is reaching till which point in my code and where is actual problem.
In java by exception handling mechanism your program doesn't terminate on exception. For example for example you can know the value of your desired variable when your program was trying to execute x/(x-y), and caught divide by zero exception.
Exception handling is necessary for string handling as there might be some unexpected situation during string handling which may lead to program crash or abrupt termination
separating error handling code from 'regular' code
Debugging a program is to correct, remove a fault, produce better security, etc, in a computer program.
Microsoft supports Structured Exception Handling (SEH) as a programming technique only at the compiler level. In particular, MS Visual C++ compiles __try, __except, and __finally as the three non-standard keywords used in this program. As well, SEH is supported by a number of WIn32 API functions including RaiseException which allows to raise any SEH exceptions manually. Overall, it is a native handling mechanism for Windows and features the "finally" mechanism that is currently not present in the standards C++ exception. SEH is set up to handle each thread of execution separately.
Here is a code snippet illustrating exception handling: try { int a= 3 / 0 ; } catch ( ArithmeticException e ) { System.out.println ("An ArithmeticException has occured"); } finally { // some code }
We use exception handling so that the program can gracefully handle any situation that may be unexpected. We use try-catch for exception handling. if-else is a conditional logic checking mechanism
An exception is abnormal program flow, so handling the exception is the very definition of resolving the abnormality.
interrupt handling is the process of handling a break or interrupt called by a program where as exception handling is for handling some exceptional conditions that'll occur when a program is running
sometimes there are situations where the program is vary long which can make error debugging a long process so java provides a facility to make user defined exception handling suppose we are dividing two numbers a/b and if the user enters the value of b 0, the user wants to display an error of your own so the user can do this by using exception handling
Exception handling is necessary for string handling as there might be some unexpected situation during string handling which may lead to program crash or abrupt termination
When an exception occurs in program execution. Such as 1/0 or divide by zero exception. The program must catch the exception or the program will crash. Although handling of the exception or solution is not necessary.
separating error handling code from 'regular' code
Debugging a program is to correct, remove a fault, produce better security, etc, in a computer program.
Microsoft supports Structured Exception Handling (SEH) as a programming technique only at the compiler level. In particular, MS Visual C++ compiles __try, __except, and __finally as the three non-standard keywords used in this program. As well, SEH is supported by a number of WIn32 API functions including RaiseException which allows to raise any SEH exceptions manually. Overall, it is a native handling mechanism for Windows and features the "finally" mechanism that is currently not present in the standards C++ exception. SEH is set up to handle each thread of execution separately.
Debugging makes the program works fast while maintainance makes the program slow
Debugging
Here is a code snippet illustrating exception handling: try { int a= 3 / 0 ; } catch ( ArithmeticException e ) { System.out.println ("An ArithmeticException has occured"); } finally { // some code }