-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLoggingExceptions2.java
More file actions
34 lines (27 loc) · 905 Bytes
/
LoggingExceptions2.java
File metadata and controls
34 lines (27 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package exceptions;
/**
* RUN:
* javac exceptions/LoggingExceptions2.java && java exceptions.LoggingExceptions2
* OUTPUT:
* Jan 14, 2015 7:10:42 AM exceptions.LoggingExceptions2 logException
* SEVERE: java.lang.NullPointerException
* at exceptions.LoggingExceptions2.main(LoggingExceptions2.java:26)
*/
import java.util.logging.*;
import java.io.*;
public class LoggingExceptions2 {
private static Logger logger = Logger.getLogger("LoggingExceptions2");
static void logException(Exception e) {
StringWriter trace = new StringWriter();
e.printStackTrace(new PrintWriter(trace));
logger.severe(trace.toString());
}
public static void main(String[] args) {
try {
throw new NullPointerException();
}
catch (NullPointerException e) {
logException(e);
}
}
}