Java exception handling and log management

Source: Internet
Author: User

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

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.