Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 133145 - Surround with try-catch needs user options
Surround with try-catch needs user options
Status: NEW
Product: java
Classification: Unclassified
Component: Hints
All All
: P2 with 29 votes (vote)
: 8.1
Assigned To: Svata Dedic
: 136402 139589 (view as bug list)
Depends on:
  Show dependency treegraph
Reported: 2008-04-17 19:29 UTC by chase
Modified: 2017-02-24 15:34 UTC (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description chase 2008-04-17 19:29:55 UTC
The code that adds when Surround with try-catch is invoked does not match the logging
strategy used by many projects. The current shortcomings are:

1) Forces the use of logging
2) Forces the use of java.util.logging
3) Forces the use of classname based loggers

There should be a user accessible gui-based configuration for the behavior of Surround with try-catch. Options I believe
would be useful:

1) A drop-down that allows the user to specify the behavior of the catch block (PrintStackTrace/Logging/Empty)
2) When logging is the selected behavior there should be a choice of java.util.logging, log4j, or Apache commons-logging
3) When logging is the selected behavior there should be a choice for the logger name (Class Name/Package Name/User Defined)
Comment 1 Jan Becicka 2008-05-15 13:25:28 UTC
Max volunteered :)
Comment 2 Jiri Prox 2008-06-04 08:10:53 UTC
*** Issue 136402 has been marked as a duplicate of this issue. ***
Comment 3 Max Sauer 2008-10-15 09:38:24 UTC
*** Issue 139589 has been marked as a duplicate of this issue. ***
Comment 4 desmond_kirrane 2009-07-23 11:10:19 UTC
Instead of hint adding 


The default code added to the catch should be

throw new RuntimeException("", ex);

Printing the stack trace will not terminate the application and the code will comtinue to run to the next line
eventhough an exception occurred.
Comment 5 chase 2009-09-22 23:24:32 UTC
Switching the version from 6.0 to 6.8 since this still needs to be enhanced.

A note from one of the duplicate bug reports for those of you that may note know about it. try/catch can be customized a
little bit in Options->Java Code->Hints->Error Fixes. At least is allows to use ex.printStackTrace(); which does not add
any import.

Maybe instead of using a gui dialog this needs to be a full blown template in order to accommodate all the possible
variations people use. In the short term I'd be almost happy if there was a option to leave the catch block completely
Comment 6 ebeb 2011-06-08 11:33:02 UTC
The current behaviour is definitely annoying. The current frame I use provides a custom logging facility and most of the time just don't want any logging at all. E.g. in Thread.wait or closing streams... But it always adds imports.

Why not use code templates for that?
Comment 7 lvr123 2012-07-04 21:26:28 UTC
Same troubles here...
Is there a template for this ?
Comment 8 Jiri Prox 2012-07-09 13:17:22 UTC
There are some options in Options-> Editor->Hints -> Surround with try-catch hint, but unfortunately no template
Comment 9 gregjohnson 2014-01-26 22:05:37 UTC
Just to keep this alive ...

can we please have a code template for this? 

Comment 10 gromit190 2017-02-24 15:34:09 UTC

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo