The code that MagicSurroundWithTryCatchFix.java 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)
Max volunteered :)
*** Issue 136402 has been marked as a duplicate of this issue. ***
*** Issue 139589 has been marked as a duplicate of this issue. ***
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.
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
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
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?
Same troubles here...
Is there a template for this ?
There are some options in Options-> Editor->Hints -> Surround with try-catch hint, but unfortunately no template
Just to keep this alive ...
can we please have a code template for this?