First, abnormal
1. What is an exception?
Exceptions to Java programs that occur during operation
2, how to do exception handling in Java?
exception handling Mechanisms in Java
Try, catch, finally, throw, throws
try{
Code with the possibility of an exception
}catch (Exception type) {
Capturing and handling exceptions that occur
Return
System.exit (1);//finally statement block will not execute
}finally{
Code to execute regardless of whether the program has an exception
}
Try...catch...finally altogether there are 3 combinations of methods
Try...catch ... (Catch can be many, but be aware of the order of subclasses stepfather classes first)
Try...catch...finally ...
Try...finally ....
Public classTest3 {Private StaticLogger Logger=logger.getlogger (Test3.class. GetName ()); Public Static voidmain (String [] args) {Scanner input=NewScanner (System.inch); System. out. Print ("Please enter dividend:"); intnum1=Input.nextint (); System. out. println (""); System. out. Print ("Please enter a divisor:"); intNum2=Input.nextint (); Try{System. out. println (num1/num2); System. out. println ("Thanks for using this program! "); }Catch(inputmismatchexception e) {logger.error ("An error has occurred! Divisor and dividend must be integers! ", E); }Catch(ArithmeticException e) {logger.error (E.getmessage ()); }Catch(Exception e) {logger.error (E.getmessage ()); }finally{System. out. println ("Happy Drink You use this program! "); } }} example
Example
3. What are the common types of exceptions? Table 6-1
4. Throw and THROWS2 keywords are all used to throw an exception
The difference has 3 points, P149 page
Different roles
Different locations
Content is different,
Ii. Log4j:1 Open Source Logging tool
Steps to use:
1. Add the log4j. jar file to the project
2. Create log4j.propterties file "Save log information Related Settings"
3. writing configuration information for logs "output level, destination, format"
4, in the program, using log4j logging (SQL log, Exception Log, business log and other 3 types of log information)
Java Object-oriented sixth chapter