testcase including fillInStackTrace and rethrow examples
authorjowenn <none@none>
Sun, 14 Mar 2004 14:22:24 +0000 (14:22 +0000)
committerjowenn <none@none>
Sun, 14 Mar 2004 14:22:24 +0000 (14:22 +0000)
tests/stack/exception.java

index 17075ba9f6f00cbfd4a6e2ae9a4ad3331d66e81d..bc65e869ff038adc60c59e0d209d8ec8372e966e 100644 (file)
@@ -8,9 +8,57 @@ public class exception {
        }
 
        public static void a() throws Exception {
-               b(1);
+               try {
+                       b(1);
+               } catch (Exception e) {
+                       System.out.println(e.getMessage());
+                       e.printStackTrace();
+                       System.out.println("Caught in a()");
+               }
+
+               b(2);
        }
 
+       public static void c() throws Exception{
+
+               try {
+                       d();
+               } catch (Exception e) {
+                       System.out.println(e.getMessage());
+                       e.printStackTrace();
+                       System.out.println("Caught in c(), rethrowing");
+                       throw e;
+               }
+
+
+       }
+
+       public static void d() throws Exception{
+               throw new Exception("Exception: value="+4);
+       }
+
+       public static void e() throws Exception{
+
+               try {
+                       f();
+               } catch (Exception e) {
+                       System.out.println(e.getMessage());
+                       e.printStackTrace();
+                       System.out.println("Caught in c(), refilling stacktrace and  rethrowing");
+                       e.fillInStackTrace();
+                       throw e;
+               }
+
+
+       }
+
+       public static void f() throws Exception{
+               System.out.println("Entering f");
+               throw new Exception("Exception: value="+5);
+       }
+
+
+
        public static void main(String args[]){
                try {
                        a();
@@ -20,7 +68,25 @@ public class exception {
                        e.printStackTrace();
                }
                try {
-                       throw new Exception("2");
+                       throw new Exception("3");
+               }
+               catch (Exception e) {
+                       System.out.println(e.getMessage());
+                       e.printStackTrace();
+                       
+               }
+
+               try {
+                       c();
+               }
+               catch (Exception e) {
+                       System.out.println(e.getMessage());
+                       e.printStackTrace();
+                       
+               }
+
+               try {
+                       e();
                }
                catch (Exception e) {
                        System.out.println(e.getMessage());