Community
Participate
Working Groups
3.2. M3 I often find myself in a situation similar to the following example (| caret location): int foo() { try { int value= compute(); } catch (Exception e) { } return value;| } This is especially true after using the "surround with" template which does not split the variable declaration like the "surround with try/catch" quick fix. But even with the latter, if I add the return statement after adding the exception handler, 'value' is out of scope. Current flow: - move to the declaration of the local var - quick assist: split declaration - move declaration to outer scope - intialize the variable, either to a default value at the declaration, or to an error value within the catch block Enhancement: - quick fix "move variable declaration to outer scope" which does steps 1-3 from above. - for the initialization, I would suggest moving the caret to the declaration so that I can add an initializer. Not sure though. Adding an initializer in the catch block is probably not the right thing, also because there may be more than one catch block etc. Expected result (|== caret location, ¦ caret exit position): int foo() { int value|; try { value= compute(); } catch (Exception e) { } return value;¦ }