Bug 548776 - Surround With try catch only surround entire scope
Summary: Surround With try catch only surround entire scope
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.12   Edit
Hardware: PC Windows 10
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-28 15:20 EDT by jonathan heindl CLA
Modified: 2023-08-03 12:20 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jonathan heindl CLA 2019-06-28 15:20:58 EDT
let say I have this block:

int doStuff(int n) throws Exception {
	if (n == 0) {
		throw new Exception();
	} else {
		return n;
	}
}

int original() {
	int number = 5;
	int newNumber = doStuff(number);
	return newNumber;
}

//now the compiler recognizes that doStuff throws a declared Exception
//and proposes a quickfix (here we choose surround with try catch)
// reesulting in this variable where you get another exception(newNumber may //not have been initialized) and your format is completely screwed
//I find myself having to fix these blocks at least 90% I use this fix

int test() {
	int number = 5;
	int newNumber;
	try {
		newNumber = doStuff(number);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return newNumber;

}
//Preferably It would look like this :
//keeping the entire function scope in the try and adding the catch at the //end

int test2() {
	try {
		int number = 5;
		int newNumber = doStuff(number);
		return newNumber;
	} catch (Exception e) {
		return 0; //whatever
	}
}
Comment 1 Eclipse Genie CLA 2021-08-12 13:53:06 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.
Comment 2 Eclipse Genie CLA 2023-08-03 12:20:39 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.