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

Bug 545163

Summary: [12][surround with try/catch] results in error with switch expression
Product: [Eclipse Project] JDT Reporter: Noopur Gupta <noopur_gupta>
Component: UIAssignee: Kalyan Prasad Tatavarthi <kalyan_prasad>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 4.11   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/142244
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=d55c08dcfcdc1388c0571f8510369d5a45be1227
Whiteboard:
Bug Depends on:    
Bug Blocks: 545120    

Description Noopur Gupta CLA 2019-03-07 06:31:13 EST
void throwing (int i) {
		int next = switch (i) {
		case 1 -> 2;
		default -> throw new Exception();
		};
	}

- Apply "surround with try/catch" proposal on the error. It results in:

	void throwing (int i) {
		int next = switch (i) {
		case 1 -> 2;
		default -> try {
				throw new Exception();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		};
	}

This gives an error (as mentioned in bug 545118).

It should be checked how to represent a try-catch in a case statement. If it is not possible to represent it then the proposal should not be shown.
Comment 1 Kalyan Prasad Tatavarthi CLA 2019-05-16 06:48:22 EDT
Not only in this case but surrounding a Throw statement with a try-catch statement is not correct. This proposal should not even be shown if the error is on a Throw Statement.
Comment 2 Eclipse Genie CLA 2019-05-16 06:50:00 EDT
New Gerrit change created: https://git.eclipse.org/r/142244