Java Learning Note day07

Source: Internet
Author: User

1.throwable the following subcategories fall into two main categories: Error and Exception

2. If there is throws Exception on the method, the exception must be handled:
try{
Need to detect exception code

}catch (Exception e) {
Handling Exception Codes

}finally{
Code that is bound to execute
}

Here, if Try{}catch () {} is not processed, and the method on which it is called continues to throwsexception
Thrown, to the end there is no method to process, always throw to the JVM virtual machine, JVM virtual machine has a default processing mechanism,
Here, the program can be compiled through, but at run time will still error, terminate the program.

3. When the method indicates that there are multiple exception classes that need to be thrown, a catch is required to catch them
You need to put the parent-child catch on the last side of multiple catch.

4. Custom Exceptions:
1) Define a exception subclass (that is, the class needs to inherit exception)
2) creates the subclass object and throws the object, causing the program to jump.
A custom exception class that requires a throw new Exception class () If a method that calls the class might have an exception in the method
and is indicated on this method, if the throw new is a subclass of the exception exception class, the method can not indicate

Differences between 5.RuntimeException anomalies and common exception anomalies
Common exception anomalies need to be detected at compile time.
And runtimeexception can not be detected at compile time.
That
There is a throw new Exception ("") within the method, which must be identified on the method.
If there is a throw new RuntimeException ("") inside the method, you can not identify the exception on the method

The difference between 6.throw and throws
1) Throw is a statement that throws an exception; throws is a method that throws an exception
2) throws can be used alone, but throw cannot
3) throw either with try-catch-finally statement supporting use, or with throws supporting use. But throws
Can be used alone, and then caught by the method that handles the exception.
The throw statement is used in the body of the method to indicate that an exception is thrown and processed by the statement in the method body.
The throws statement is used after the method declaration, which means that the exception is thrown and handled by the caller of the method.
Throws primarily declares that this method throws an exception of this type so that its caller knows to catch the exception.
Throw is a specific action that throws an exception, so it is throwing an exception instance.

7. Exception Handling Details:
1) If a method in the parent class does not throws throw an exception, the child class cannot overwrite the method throws throw an exception, only try, not throw. (That is, what the parent does not do, the subclass cannot do)
2) When a subclass overrides a parent class, only the subclass of the parent exception or exception is thrown
3) If the parent throws multiple exceptions, the subclass can only throw these exception subsets

Java Learning Note day07

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.