Exception Description Program exceptions: Throwable serious problem: Error we do not handle. This kind of problem is usually very serious, for example memory overflow. Issue: Exception compile-time problem: The exception that is not runtimeexception must be handled, because you do not process, the compilation cannot pass. Run-time issue: runtimeexception This problem we also do not deal with, because it is your problem, and this problem appears certainly is our code is not rigorous, need to fix the code. The code structure of the exception
Try {
Code that may be problematic;
}catch (Exception name variable) {
deal with the problem;
}finally {
releasing resources;
}
After the problem is found in the try, the JVM will help us generate an exception object and then throw the object and match the class in the catch. If the object is of a certain type, the processing information inside the catch is executed. Several methods to understand in the Exception class: public string GetMessage (): Exception message string public string toString (): A simple information description that returns an exception that contains the following information: The name of the class of this object (full pathname) ":" (a colon and a space) invokes the result of this object Getlocalizedmessage () method (the contents of GetMessage () are returned by default) Prin Tstacktrace () Gets the exception class name and exception information, and where the exception appears in the program. return value void. Output information to the console. The problem of finally statement block: Finally: The body of the statement that is finally controlled must be executed. Note: If the JVM exits before executing to finally, it cannot be executed. For example, there are system.exit (0) in catch;
Note: Return does not return the function immediately, but the return statement executes, and the returned result is placed in the function stack, where the function does not return immediately, and it does not actually begin to return until the finally statement is executed.
Dark Horse programmer-java Base-exception