1

The default exception handling code generated by Eclipse looks as follows:

try {
    methodThrowsACheckedException();
} catch (SomeCheckedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Would it not be better if Eclipse generated the following code instead?

try {
    methodThrowsACheckedException();
} catch (SomeCheckedException e) {
    // TODO Auto-generated catch block
    throw new RuntimeException(e);
}
3
  • 2
    Why do you think so? Why would you want to rethrow a checked exception as a RuntimeException? Commented Oct 3, 2012 at 9:21
  • I don't think so: turning a checked exception into an unchecked one probably would be cause for some heated discussions! ;) Commented Oct 3, 2012 at 9:23
  • Checked vs unchecked arguments aside, I think we can agree that simply printing the stacktrace and moving along is less than ideal. Commented Mar 26, 2014 at 19:47

1 Answer 1

6

You can configure eclipse to do that its your choice. Check Code Template-> Catch Block Body in Preferences->Java->Code style

Sign up to request clarification or add additional context in comments.

1 Comment

Both appears same to me generating RuntimeException from Exception class is a code smell. So is just doing printStackTrace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.