1. What is an exception?
Exceptions are things that prevent the program from running properly, and when an exception occurs, the program will terminate and the system will form some error messages, and the best thing for the exception is that they can be processed.
2. When does an exception occur?
Exceptions can occur at run time (runtime exceptions) or at compile time (Compile-time exception)
3. Cause of the exception
There are some reasons for an exception, for example, the following situation will cause an exception, open a nonexistent file, network connectivity issues,
The operation has exceeded the predefined range, the class file has not been found, and so on.
4. Differences between errors and exceptions
Error: Represents some of the issues that the app should not handle, which are not expected to be handled in the usual circumstances, such as: Memory errors,
Hardware problems, JVM issues, and so on.
Exceptions: Exceptions are included in the code, and developers can handle such problems using the correct method, such as the following exception, DivideByZero exception NullPointerException ArithmeticException ArrayIndexOutOfBoundsException
5. Benefits of Exception handling
Exception handling allows us to control the flow of the program.
6. Why Handle Exceptions
is to return friendly warning messages to the user, in most cases due to user-supplied error data that caused the exception to occur.
7. Types of exceptions
Detectable exceptions
Non-detectable exception
Except that runtime exceptions are called detectable exceptions, such as:
ClassNotFoundException
IllegalAccessException
NoSuchFieldException
EOFExceptionetc.
Runtime exceptions are called non-detectable exceptions, such as:
ArithmeticException
ArrayIndexOutOfBoundsException
NullPointerException
NegativeArraySizeExceptionetc.
Exception Handling in Java