shortcut keys: Ctrl+d Delete the line where the cursor is located
alt+/Smart Tips
Exception handling
An exception is an issue that prevents the current method or scope from continuing to execute, and some instructions in the program that cause the program to break.
Try and Catch keywords
try{
Code snippet with possible exception
}catch (Exception type Object) {
Handling Operations for exceptions
}...
finally{
Anomaly of the unified export
}
Cases:
1 Public classPractice14 {2 3 Public Static voidMain (string[] args) {4 //TODO auto-generated Method Stub5 Try{6 intnum1=10;7 intNum2=0;8System.out.println (num1/num2);9}Catch(ArithmeticException e) {TenSystem.out.println ("Arithmetic Operation exception"); One } A finally{ - //finally: You can do some recycling cleanup here -SYSTEM.OUT.PRINTLN ("Finally statement will execute whether or not an exception occurs.")); the } - } - -}
Throw and throws keywords:
The throws keyword is primarily used on the declaration of a method, which means that the exception is not handled in the method and is left to the call processing.
The Throw keyword indicates that an exception is thrown manually in the program, because the exception from the processing mechanism, once all exceptions are generated, is actually thrown by an instantiated object of an exception class, then this object can also be thrown directly from the throw.
1 Public classPractice14 {2 3 Public Static voidMain (string[] args) {4 //TODO auto-generated Method Stub5 //exTest ();6 Try {7 intResult=extest2 (10,2);8 System.out.println (result);9}Catch(Exception e) {Ten //TODO auto-generated Catch block One e.printstacktrace (); A } - } - Private Static intExTest2 (intNUM1,intNUM2)throwsexception{ the if(num2==0)Throw NewArithmeticException ("Divisor cannot be 0"); - returnnum1/num2; - } - Private Static voidexTest () { + Try{ - intnum1=10; + intNum2=0; ASystem.out.println (num1/num2); at}Catch(ArithmeticException e) { -System.out.println ("Arithmetic Operation exception"); - } - finally{ - //finally: You can do some recycling cleanup here -SYSTEM.OUT.PRINTLN ("Finally statement will execute whether or not an exception occurs.")); in } - } to +}
Eclipse and Exception handling