Java exception handling and log4j configuration files

Source: Internet
Author: User

First, the program error

    1. Warning: Yellow Line: Warning
    2. Error: Resource class: System level (thread)/ Environment level (drawing)
    3. exception: Compile level: Exception

Run Level: Exception-RuntimeException

Second, abnormal operation

    1. Enter an unmatched exception: Inputmismatchexception
    2. Arithmetic Exceptions: ArithmeticException:/By zero
    3. Array subscript out- of-bounds exception: ArrayIndexOutOfBoundsException
    4. number Format exception: NumberFormatException
    5. NULL pointer exception: NullPointerException
    6. there is no exception to the bytecode file: ClassNotFoundException
    7. Wait a minute...

Third, exception handling

    1. Throw :throw Exception /throws declaration exception
    2. catch:try...catch...finally ...
    3. Exception class Genealogy

Iv. log files

    1. Create Folder Lib
    2. Check in the log4j jar package
    3. Adding a jar package to the compilation path (add tobuildpath)
    4. Create configuration file:log4j.properties
    5. Edit configuration information Open the Log4j.properties file, write in source

Log4j.rootlogger=debug, stdout,logfile

Log4j.appender.stdout=org.apache.log4j.consoleappender

Log4j.appender.stdout.target=system.err

Log4j.appender.stdout.layout=org.apache.log4j.simplelayout

Log4j.appender.logfile=org.apache.log4j.fileappender

Log4j.appender.logfile.file=jbit.log

Log4j.appender.logfile.layout=org.apache.log4j.patternlayout

log4j.appender.logfile.layout.conversionpattern=%d{yyyy-mm-dd HH:mm:ss}%l%F%p%m%n

Use

    1. To create a Log object property in a class that requires logging information

Import Org.apache.log4j.Logger

Public Logger log = Logger.getlogger ( class name . Class.getname ());

Log.error (String errmessage);

Log.error (String errmessage, Exception e);

Java exception handling and log4j configuration files

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.