1

In trying to debug a section of code today, I discovered I had written this:

if (testHand[iThread].wasThreadInterrupted()) throw(new InterruptedException());

instead of:

if (testHand[iThread].wasThreadInterrupted()) throw new InterruptedException();

Interestingly this compiled and ran with no problems, but probably wasn't doing what I intended. I've searched for a throw method, but haven't found one - is this some bad way of throwing an exception..why did it compile?

Opus1217
  • 723
  • 4
  • 17
  • 1
    Possible duplicate of [The throws keyword for exceptions in Java](http://stackoverflow.com/questions/1989077/the-throws-keyword-for-exceptions-in-java) – Dennis Kriechel Dec 05 '15 at 05:56
  • 4
    You can put parentheses `(` and `)` around any expression. It doesn't mean anything special. Does it looks less strange if there would have been a space after `throw`? `throw (new InterruptedException());` – Jesper Dec 05 '15 at 06:05
  • Ah of course. Thanks for the quick explanation. – Opus1217 Dec 05 '15 at 06:08
  • comment by Jesper should probably posted as "answer" instead of comment so it can be marked as correct – loonytune Dec 05 '15 at 09:01
  • If Jesper does, I will mark as such – Opus1217 Dec 05 '15 at 14:55

0 Answers0