-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExceptionMethods.java
More file actions
35 lines (30 loc) · 1.03 KB
/
ExceptionMethods.java
File metadata and controls
35 lines (30 loc) · 1.03 KB
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
35
package exceptions;
/**
* RUN:
* javac exceptions/ExceptionMethods.java && java exceptions.ExceptionMethods
* OUTPUT:
* Catched!
* getMessage(): My Exception
* getLocalizedMessage(): My Exception
* toString(): java.lang.Exception: My Exception
* printStackTrace():
* java.lang.Exception: My Exception
* at exceptions.ExceptionMethods.main(ExceptionMethods.java:18)
*/
// import java.util.logging.*;
// import java.io.*;
public class ExceptionMethods {
public static void main(String[] args) {
try {
throw new Exception("My Exception");
}
catch (Exception e) {
System.out.println("Catched!");
System.out.println("getMessage(): " + e.getMessage());
System.out.println("getLocalizedMessage(): " + e.getLocalizedMessage());
System.out.println("toString(): " + e);
System.out.println("printStackTrace(): ");
e.printStackTrace(System.out);
}
}
}