-
what is exception?
an exception is an abnormal event that occurs during the execution of a program which disrupts the normal flow of instructions. In simpler words, it’s a problem or error that happens while your program is running.-
why use ?
We use exceptions in Java to handle errors and abnormal situations gracefully, instead of letting the program crash. Think of exceptions as a safety net for your program.
-
when use exception?
ou use exceptions whenever there’s a chance that the user might enter data in the wrong format, which would normally crash your program.
Error
1) System-level serious problem
2) Cannot handle
3) JVM, memory, hardware
4) Examples OutOfMemoryError, StackOverflowError
5) Usually program crashexception
1) abnormal event
2) Can handle using try-catch
3) Programmer mistake, unexpected input
4) ArithmeticException, NullPointerException
5) Can continue if handled -
-
Throw, and Try...Catch...Finally
The try statement defines a code block to run (to try).
The catch statement defines a code block to handle any error.
The finally statement defines a code block to run regardless of the result.
The throw statement defines a custom error.
Top comments (0)