Java Exception Review

Source: Internet
Author: User

1. Check for exceptions: exceptions that will be found at compile Time. Custom Check exceptions inherit Excepiton.

2. Non-check Exception: The exception that is generated at run Time. Runtimeexcepiton and its subclasses, custom non-inspection exceptions to inherit Runtimeexcepiton.

3, Catch the exception: if there is a possible exception, the general compiler will give you the Try/catch box.

Try{//may produce an exception to the Statement}catch (Exception e) {//catch exception, The operation of the Exception}finally{//exception action to play, the statement that must be executed, such as the shutdown IO or something}

4, finally: not Necessary. typically, the statements inside the catch are executed before the finially is Executed. If the first sentence in the catch is return, then the finally is executed First.

5. Throws: If a function throws an inspection exception, it needs to be declared with throws declaration of the exception to be thrown for external capture and Processing.

6, Throw: throw an exception directly.

Package Exceptiontest;public class main {public static void main (String Args[]) {int a[] = new Int[2];a[0]=1;a[1]=2;//simple capture exceptions, and methods for using exception objects Try{system.out.println (a[3]);} Catch (Exception e) {System.out.println (e);} Finally{system.out.println ("exception! ");} External processing test throws an exception inside the try {test ();} catch (Exception e) {System.out.println (e);}} Static class MyException extends Exception{public myexception () {super ();} Public String toString () {return ' myexception ';}} If a function may throw an inspection exception, you must use the static inner class public static void Test () throws exception{myexception e = new MyException in the throws Declaration//static Method. (); Throw e;}}

Java Exception Review

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.