Java Exception Handling

Source: Internet
Author: User

1. Exception: A flow of instruction that causes a program to break, and once an exception is generated and is not handled properly, the program interrupts execution;
2. Exception Handling
try{
//statements that may appear abnormal
}[catch (Exception Object object) {
//Exception handling
}][finally{
//Exception Unified export code, will execute
}]
3. All exceptions are throwable subclasses, Throwable have two subclass error and exception;
What is the difference between error and exception?
error: Is a bug that occurs when the program is not executed, generally refers to the JVM error, the user can not process;
Exception: Refers to the exception that occurs during the execution of the program, and the exception handling is done for this type;
in the future work, can deal with the biggest anomaly is exception;
4. Exception Handling Process:
1) When an exception is generated in the program, a specified exception class object is automatically instantiated by the JVM based on the exception type;
5.throws: This keyword tells the user what exceptions are possible in a method, often at the declaration of a method;
when the method is transferred, exception handling must be done, the main method can also add throws exception, the main method is the default processing by the JVM;
Throw: Artificial exception thrown, such as throw, then there are the following two options:
1) Use throws on the method to continue to throw;
2) manual use of abnormal handling;
the difference between throw and throws:
1) Throw is used in the method body, indicating that an exception class object is thrown by hand;
2) throws is used in the declaration of a method to indicate that this method must be handled abnormally at the time of invocation;
The 6.runtime exception is a selective exception and will not be error-prone at compile time, but can be faulted at execution time;
the difference between exception and runtimeexception?
RuntimeException is a subclass of exception;
exception exceptions require mandatory processing, while subclasses under RuntimeException do not require mandatory processing when writing code, and if they are not processed by the JVM;
7. Generics: A property in a class or a parameter of a method, when the class definition does not set the specific type, only a token, and when the class is used for its dynamic binding of a data type;
a wildcard character? : Cannot modify data, but can fetch data
? Extends class: Sets the line of generics, used in the Set class or method parameters;
? Super class: Sets the lower bound of the generic type, used in the method parameters;

Java Exception Handling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.