java exceptions, exception handling mechanism

Any kind of programming language design program, errors may occur at run time.

Ideally capture errors at compile time, but some errors will occur only at run time.

For these errors, there are two solutions:

  An error was encountered on the termination of running programs.

  By the programmer when writing programs to take into account errors detected, an error message, and error handling.

java abnormal

  In the java language, will not normally occur in the implementation of the program called "anomaly."

  java Exception handling the case for the unexpected, such as the file is not found, network errors, illegal parameters.

Java program is running abnormal events that occur can be divided into two categories:

  Error: JVM internal system error, resource depletion and other serious conditions.

  Exception: other general problems caused by programming errors or accidental external factors.

  For example: a null pointer access, trying to read the file does not exist, the network connection is interrupted.

 

Exception handling mechanism

  Java exception handling model provides is caught throwing.

  Java program execution such as abnormal, will automatically generate an exception class object, the object will be presented to the exception java runtime system, a process known as throw (the throw) is abnormal.

  If a method throws an exception, the exception will be thrown into the call method. If the exception is not handled in the calling process, it continues to be thrown to the caller calls the method, and this process will continue indefinitely, knowing that the exception is handled. This process is called capture (catch) exceptions.

  If an exception back to the main () method, and the main () does not handle, the program run is terminated.

  Programmers usually only deal with Expcetion, while Error powerless.

Guess you like

Origin www.cnblogs.com/fangfangfanga/p/12142814.html