KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > util > logging > ErrorManager


1 /*
2  * @(#)ErrorManager.java 1.8 04/02/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8
9 package java.util.logging;
10
11 /**
12  * ErrorManager objects can be attached to Handlers to process
13  * any error that occur on a Handler during Logging.
14  * <p>
15  * When processing logging output, if a Handler encounters problems
16  * then rather than throwing an Exception back to the issuer of
17  * the logging call (who is unlikely to be interested) the Handler
18  * should call its associated ErrorManager.
19  */

20
21 public class ErrorManager {
22    private boolean reported = false;
23
24     /*
25      * We declare standard error codes for important categories of errors.
26      */

27
28     /**
29      * GENERIC_FAILURE is used for failure that don't fit
30      * into one of the other categories.
31      */

32     public final static int GENERIC_FAILURE = 0;
33     /**
34      * WRITE_FAILURE is used when a write to an output stream fails.
35      */

36     public final static int WRITE_FAILURE = 1;
37     /**
38      * FLUSH_FAILURE is used when a flush to an output stream fails.
39      */

40     public final static int FLUSH_FAILURE = 2;
41     /**
42      * CLOSE_FAILURE is used when a close of an output stream fails.
43      */

44     public final static int CLOSE_FAILURE = 3;
45     /**
46      * OPEN_FAILURE is used when an open of an output stream fails.
47      */

48     public final static int OPEN_FAILURE = 4;
49     /**
50      * FORMAT_FAILURE is used when formatting fails for any reason.
51      */

52     public final static int FORMAT_FAILURE = 5;
53
54     /**
55      * The error method is called when a Handler failure occurs.
56      * <p>
57      * This method may be overriden in subclasses. The default
58      * behavior in this base class is that the first call is
59      * reported to System.err, and subsequent calls are ignored.
60      *
61      * @param msg a descriptive string (may be null)
62      * @param ex an exception (may be null)
63      * @param code an error code defined in ErrorManager
64      */

65     public synchronized void error(String JavaDoc msg, Exception JavaDoc ex, int code) {
66     if (reported) {
67         // We only report the first error, to avoid clogging
68
// the screen.
69
return;
70     }
71     reported = true;
72     String JavaDoc text = "java.util.logging.ErrorManager: " + code;
73     if (msg != null) {
74         text = text + ": " + msg;
75     }
76     System.err.println(text);
77     if (ex != null) {
78         ex.printStackTrace();
79     }
80     }
81 }
82
Popular Tags