Community
Participate
Working Groups
When the ternary operator ( ?: ) is called with a void function as one of the last operands, the error given in the java perspective is: No exception of type void can be thrown; an exception type must be a subclass of Throwable This is misleading since the problem is one of a malformed statement (or not a statement at all), rather than anything obviously exception related.
This will show the problem: public class Snippet { private static void voidA() { } private static void voidB() { } private static boolean b = false; public static void method() { int i = 0; switch(i) { case 0: b ? voidA() : voidB(); break; } } }
I agree this error is misleading. Note though that there was a primary syntax error reported just above: case 0: ^ Syntax error on token ":", throw expected after this token The misleading error is a secondary error induced by the statement recovery.
Statement recovery did produce a strange construction: public static void method() { int i = 0; switch (i) { case 0 : ; throw (b ? voidA() : voidB()); break ; } }
Changing Version tag to something more believable.
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.