Skip to main content
added 160 characters in body
Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k

The premise of the question is flawed, because catching Exception does catch RuntimeException. Demo code:

public class Test { public static void main(String[] args) { try { throw new RuntimeException("Bang"); } catch (Exception e) { System.out.println("I caught: " + e); } } } 

Output:

I caught: java.lang.RuntimeException: Bang 

Your loop will have problems if:

  • callbacks is null
  • anything modifies callbacks while the loop is executing (if it were a collection rather than an array)

Perhaps that's what you're seeing?

The premise of the question is flawed, because catching Exception does catch RuntimeException. Demo code:

public class Test { public static void main(String[] args) { try { throw new RuntimeException("Bang"); } catch (Exception e) { System.out.println("I caught: " + e); } } } 

Output:

I caught: java.lang.RuntimeException: Bang 

The premise of the question is flawed, because catching Exception does catch RuntimeException. Demo code:

public class Test { public static void main(String[] args) { try { throw new RuntimeException("Bang"); } catch (Exception e) { System.out.println("I caught: " + e); } } } 

Output:

I caught: java.lang.RuntimeException: Bang 

Your loop will have problems if:

  • callbacks is null
  • anything modifies callbacks while the loop is executing (if it were a collection rather than an array)

Perhaps that's what you're seeing?

Source Link
Jon Skeet
  • 1.5m
  • 893
  • 9.3k
  • 9.3k

The premise of the question is flawed, because catching Exception does catch RuntimeException. Demo code:

public class Test { public static void main(String[] args) { try { throw new RuntimeException("Bang"); } catch (Exception e) { System.out.println("I caught: " + e); } } } 

Output:

I caught: java.lang.RuntimeException: Bang