Skip to content

Seemingly puzzling exception handling behavior that appears sensitive to try block content #3441

Description

@laeubi

I'm not sure this is a new behavior and actually a feature, but has created some confusion on my side and I can't remember to have such thing in the past.

Eclipse SDK

Version: 2025-03 (4.35)
Build id: I20241203-1800

Consider the following code snippet:

public static void main(String[] args) {
	try {
		//throw new Exception();
		//new FileOutputStream("");
	} catch(Exception e) {
		throw e;
	}
}

this code compiles without any error or warning!

Now comment in the first line

public static void main(String[] args) {
	try {
		throw new Exception();
		//new FileOutputStream("");
	} catch(Exception e) {
		throw e;
	}
}

this results in what I have expsected in the first place
grafik

now use the second line:

public static void main(String[] args) {
	try {
		//throw new Exception();
		new FileOutputStream("");
	} catch(Exception e) {
		throw e;
	}
}

this gives a little different hint:
grafik

and even if it talks about FileNotFoundException, if I apply the quickfix I get this

public static void main(String[] args) throws Exception {
	try {
		//throw new Exception();
		new FileOutputStream("");
	} catch(Exception e) {
		throw e;
	}
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions