Java Foundation-Exception class--exception concept, general format, some methods of Throwable class

Source: Internet
Author: User
Tags getmessage throwable

Brief introduction:

1, the concept of abnormal

Exceptions: Problems--abnormal---are encapsulated into objects;

The object that Java describes to different abnormal situation is embodied;

for serious exceptions, Java is described by the error class-------generally do not write targeted code to handle it

for non-critical unhandled exceptions, Java is described by the exception class--and can be handled using targeted code

System: Object<--throwable<--error/exception

2. General format

try{* *}

catch (Exception class variable) {* Handling problem *}

finally{* Statements that must be executed; *}

3. Some methods of Throwable class

String getMessage()

Returns the detail message string of this throwable.

void printStackTrace()

Prints this throwable and its backtrace to the standard error stream.

String toString()

Returns A short description of this throwable.

Exceptiontest.java
 Public classExceptiontest { Public Static voidMain (string[] args) {//Detection        Try{            intResultd = Divdemo.div (10, 0); System.out.println ("Resultd ' value is:" +Resultd); }        //the receiver intercepts the exception object and then handles the problem and executes it down.         Catch(Exception e) {System.out.println ("Get it:" +e.getmessage ()); System.out.println ("Get it:" +e.tostring ());  E.printstacktrace (); 
            // print three information----exception name, exception information, where                  the exception occurred
            // In fact JVM default exception handling mechanism: is the trace information                      on the stack that calls the Printstacktrace () method//Print exception }                System.out.println ("over!" );    }} class divdemo{        publicstaticint div (int A,int b) {        return A/b;       }}

: Console:

Java Foundation-Exception class--exception concept, general format, some methods of Throwable class

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.