We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 617cc8e commit 56ba64aCopy full SHA for 56ba64a
ChainedException.java
@@ -0,0 +1,29 @@
1
+// Java program to demonstrate working of chained exceptions
2
+public class ChainedException
3
+{
4
+ public static void main(String[] args)
5
+ {
6
+ try
7
8
+ // Creating an exception
9
+ NumberFormatException ex =
10
+ new NumberFormatException("Exception");
11
+
12
+ // Setting a cause of the exception
13
+ ex.initCause(new NullPointerException(
14
+ "This is actual cause of the exception"));
15
16
+ // Throwing an exception with cause.
17
+ throw ex;
18
+ }
19
20
+ catch(NumberFormatException ex)
21
22
+ // displaying the exception
23
+ System.out.println(ex);
24
25
+ // Getting the actual cause of the exception
26
+ System.out.println(ex.getCause());
27
28
29
+}
0 commit comments