Search code examples
javaexceptionthrow

Difference between "throw(e)" and "throw e"?


I came across this rethrown exception and am surprised that it even compiles.

} catch(SomeException e) {
    ...
    throw(e);
}

Is there any difference between this throw() and what is normally used?...

} catch(SomeException e) {
    ...
    throw e;
}

Any links to where this is documented or guidance on choosing one over the other?


Solution

  • Quite a few languages allow as many parenthesis around expressions as you want. Java is one of them. The following is perfectly valid code.

    public class HelloWorld {
      public static void main(String[] args) {
        throw ((((new RuntimeException()))));
      }
    }
    

    So there's absolutely no difference, except that your source file is two bytes larger.