KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Why are some exceptions in Java not caught by catch (Exception ex) ? This is code is completely failing out with an unhandled exception. (Java Version 1.4). public static void main(String[] args) { try { //Code ... } catch (Exception ex) { System.err.println("Caught Exception"); ex.printStackTrace(); exitCode = app.FAILURE_EXIT_CODE; } finally { app.shutdown(); } System.exit(exitCode); } I get a Exception in thread "main" java.lang.NoSuchMethodError But this works public static void main(String[] args) { int exitCode = app.SUCCESS_EXIT_CODE; try { //Code ... } catch (java.lang.NoSuchMethodError mex){ System.err.println("Caught NoSuchMethodError"); mex.printStackTrace(); exitCode = app.FAILURE_EXIT_CODE; } catch (Exception ex) { System.err.println("Caught Exception"); ex.printStackTrace(); exitCode = app.FAILURE_EXIT_CODE; } finally { app.shutdown(); } System.exit(exitCode); } I get Caught NoSuchMethodError java.lang.NoSuchMethodError: I thought catching exceptions would catch all exceptions? How can I catch all exceptions in java?
Tags (comma-separated)
Save Edits
Cancel