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