Background introduction:
In the use of some Java libraries, you will find that some library use must add try-catch or throw keyword.
Abstract describes the problem:
Problem Abstraction:
1 class repository authors can detect problems in the run, but do not know how to handle the problem.
2 Using this class repository users know how to deal with this problem, but do not know how to detect them
Solve:
The effect of an exception (exception) is to solve this problem.
1 If a method does not determine how to handle the problem of non-normal processes in the program, then it can throw the problem (throw) to the caller to handle.
2 If the caller is unwilling to process then it can continue to throw (throw) to the next caller, or if willing to handle the problem then receive (catch) this
Problem, and then proceed with processing.
Java Exception hierarchy
1 Note: The exceptions we are concerned with are non-error and runtime exceptions, i.e. checkedexception (exceptions that can be detected by the compiler)
2 error usually refers to unrecoverable errors, such as exceeding the upper bounds of system performance. This error is thrown by the system.
3 RuntimeException is a problem with programmer code such as null pointers
Specific operation:
The checkedexception in Java is an object.
So when you throw an exception, you need to first select the appropriate exception type, and then the generated instance throws
Try { // } catch (Exceptiontype e) { // Exception handling code }
Run the process:
When the code encounters an exception, it ignores the code behind it and jumps directly to its corresponding catch.
A complete example:
Except 0 exception handling
Public class javaexceptiontest { publicstaticvoid main (string[] args) { // TODO auto-generated Method stub Try { double a=1/0; } Catch (arithmeticexception e) { System.out.println (e.getmessage ()); }}}
Exception categories for Java:
Http://www.tutorialspoint.com/java/java_builtin_exceptions.htm
Java Exception Teaching Documentation
Http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html
Java Exception Handling