Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 495528

Summary: Change default catch block template to throw RuntimeException instead of swallowing
Product: [Eclipse Project] JDT Reporter: Nobody - feel free to take it <nobody>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jarthana
Version: 4.6   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Nobody - feel free to take it CLA 2016-06-06 06:53:06 EDT

    
Comment 1 Nobody - feel free to take it CLA 2016-06-06 06:57:45 EDT
I don't want to start a debate about the usefulness on checked exceptions.

There are some very good arguments in this post (which I'm linking, as I'm quoting from it):
http://stackoverflow.com/a/614494/2095738 (pro)
http://stackoverflow.com/a/614330/2095738 (contra)

What both sides agree on and what every Java developer has learned from experience is that swallowing checked exceptions is about the worst solution. And yet this is exactly what the Eclipse IDE does.


    [Get] in the habit of whenever you have to handle a checked exception and you're feeling lazy (or you think the API programmer was overzealous in using the checked exception in the first place), don't just swallow the exception, wrap it and rethrow it.

    try {
        overzealousAPI(thisArgumentWontWork);
    } catch (OverzealousCheckedException e) {
        throw new RuntimeException(e);  
    }

    Put this in one of your IDE's little code templates and use it when you're feeling lazy. This way if you really need to handle the checked exception you'll be forced to come back and deal with it after seeing the problem at runtime. Because, believe me (and Anders Hejlsberg) you're never going to come back to that TODO in your

    catch (Exception e) { /* TODO deal with this at some point (yeah right) */}
Comment 2 Jay Arthanareeswaran CLA 2016-06-06 07:01:33 EDT
I am sorry, is there a bug report or enhancement request here? If so, can you clearly state what you would like Eclipse to do here?
Comment 3 Nobody - feel free to take it CLA 2016-06-06 08:00:07 EDT
This is an enhancement request. Sorry if this is not the appropriate place to report these.

Swallowing checked exceptions is not considered 'good practice' in Java. 

For that reason, Eclipse - being a Java IDE - should change its default template for a catch block from "swallow and print something" to "rethrow unchecked".
Comment 4 Jay Arthanareeswaran CLA 2016-06-07 00:48:46 EDT
(In reply to Tim De Backer from comment #3)
> This is an enhancement request. Sorry if this is not the appropriate place
> to report these.

It is. Sorry, I didn't pay close attention to the bug summary. Moving to UI where the templates belong.
Comment 5 Eclipse Genie CLA 2019-10-11 01:51:41 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.