This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

catching exceptions in main() causes segfault?



Can anybody who understands GCC's exception handling better than I do
explain this?

Program 1: segfaults, apparently in longjmp() [tries to jump to invalid addr]

  public class test {

      public static void run() throws Exception {
          throw new Exception();
      }

      public static void main(String[] s) {
          try {
              try { Thread.sleep(1000); } catch (Exception e) { }
              run();
          } catch (Exception e) {
              System.out.println("caught!!!");
              System.out.println(e);
          }
      }
  }

Program 2: runs correctly

  public class test {

      public static void run() {
          try {
              try { Thread.sleep(1000); } catch (Exception e) { }
              throw new Exception();
          } catch (Exception e) {
              System.out.println("caught!!!");
              System.out.println(e);
          }
      }

      public static void main(String[] s) {
          run();
      }
  }


So it appears that I can't catch exceptions in main(), but anywhere
else works (even in other threads).

Wierd, huh?

  - a


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]