Handling of exceptions
1. For exception handling, one can directly handle
The second can be thrown ,
Exception/io,sql, two large classes, compiled and run-time,
And the way to handle it: You can use your own defined method, or the system's
1-2. The way you define yourself is: Class Mye extends Exception (String msg) {
Super (MSG);
}
When used, it is the IF (a>0) {throw new Mye ("A cannot be greater than 0, please check");}
——————————————————————————————————————————
1-2 the system is: Try{}catch () {}
______________________________________________________________
If you want to throw it to someone else, it's void div (int a, int b) throws exception{}
When you call this method, you have to write the try .... or throw it,
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
2. Log
1. The first is to import Log4j.properties and Log4j.jar two files into the project.
2. The specific code is to get the path,
String filepath=test.class.getresource ("\"). GetPath ();
Where to put the Propertyconfigurator (). Configure (filepath+ "log4j.properities");
or replace it with ("d:/log4j.properities"); fixed in one position
Logger Lol=null;
try{
Lol=logger.getlogger (Test.class);//The error log for that file.
Code may have an exception code
}catch () {
Lol.debug (E.getmessage ());
}
Java exception handling and log management