"Thinkinginjava" 25, log abnormal output to logs

Source: Internet
Author: User

/*** Book: Thinking in Java * Function: Log the exception output to the journal. * File: loggingexceptions.java* time: April 8, 2015 21:11:51* Author: cutter_point*/package Lesson12_error_handling_with_ Exceptions;import Java.io.printwriter;import Java.io.stringwriter;import Java.util.logging.logger;class Loggingexception extends exception{private static Logger Logger = Logger.getlogger ("loggingexception");p ublic Loggingexception () {StringWriter trace = new StringWriter ();p rintstacktrace (new PrintWriter (trace)); Logger.severe ( Trace.tostring ());}} public class Loggingexceptions{public static void Main (String [] args) {try {throw new loggingexception ();} catch (Logginge Xception e) {System.err.println ("caught" + e);} Try {throw new loggingexception ();} catch (Loggingexception e) {System.err.println ("caught" + E);}}}



Output:

May 04, 2015 3:53:49 pm lesson12_error_handling_with_exceptions. Loggingexception <init>
Serious: lesson12_error_handling_with_exceptions. Loggingexception
At Lesson12_error_handling_with_exceptions. Loggingexceptions.main (LOGGINGEXCEPTIONS.JAVA:32)

Caught lesson12_error_handling_with_exceptions. Loggingexception
May 04, 2015 3:53:49 pm lesson12_error_handling_with_exceptions. Loggingexception <init>
Serious: lesson12_error_handling_with_exceptions. Loggingexception
At Lesson12_error_handling_with_exceptions. Loggingexceptions.main (loggingexceptions.java:41)

Caught lesson12_error_handling_with_exceptions. Loggingexception






"Thinkinginjava" 25, log abnormal output to logs

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.