Community
Participate
Working Groups
Build Identifier: Xtend2 SDK 2.0.0.v201105171404 xtend2: override void doGenerate(Resource resource, IFileSystemAccess fsa) { .... // auf ruf einer method die eine exception throwed // z.B. SQLException throw new MyException() } java: public void doGenerate(final Resource resource, final IFileSystemAccess fsa) throws IllegalArgumentException, MyException { { Bug: of course, an overwritten method cannot throw more exception as defined in the super-class Reproducible: Always
Workaround : Catch exceptions
For SR2, at least a validation rule, telling the user, that a certain exception must be caught, would be good. We should also allow having a throws clause (post SR2).
First shot pushed to MASTER. I've uncommented CompilerTest.testRethrownCheckedExceptions_00() CompilerTest.testRethrownCheckedExceptions_01()
Xtend functions now can declare thrown exceptions, which are compiled to Java, too. Checked exceptions in function bodies must be declared. Declared exceptions from overriden functions are validated. Checked exceptions thrown inside a function are validated against the declared ones. In Xbase, closures can no longer throw checked exceptions. Validation ensures this. This is a semantic change in Xtend, so please revise. I've uncommented CompilerTest.testRethrownCheckedExceptions_00() CompilerTest.testRethrownCheckedExceptions_01() which test that checked exceptions are rethrown by the callers (which is no longer the case). If we agree on these changes, I'm going to clean up the compiler stuff for rethrowing.
Looks good. Please clean up the part in the compiler you mentioned. A quick fix for adding a throw-clause resp. a try-catch would be nice as well.
Cleaned up rethrow in compiler and added quickfix for "Add throws declaration"
Pushed quick fix "sourround with try/catch"
I changed my mind (sorry for that) I think we should deactivate the check until we have preferences, so that users can deice whether they want to have an error, warning or nothing at all for unchecked exceptions. The compiler should always be able to compile and use the sneaky throw technique from Lombok, whenever a checked exception wasn't declared but might be thrown. https://github.com/rzwitserloot/lombok/blob/master/src/core/lombok/Lombok.java
The validation for checked exceptions is activated in Xbase by default and set to inactive for Xtend. As soon as we have preferences the User should decide on that (still default should be 'ignore'). I added the mentioned sneakyThrow to the compiler, such that regardless of the validation the compiler is always able to generate valid Java code. The quick fixes and the like are still all very valuable but we shouldn't add additional ones for now (like add catch clause to existing try-catch).
Quick fixes work fine when validation for checked exceptions is enabled.
Closing all bugs that were set to RESOLVED before Neon.0