This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes 'throws' clause specified; exception not thrown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " Watch " New topic

'throws' clause specified; exception not thrown

Hilary Mann

Joined: Jun 07, 2012
Posts: 13
I was going through my buddy's old SCJP notes and found
"When a method is declared to throw exception, it must throw it; else compiler will force you to do so."

I did not understand and this code runs fine:

Did I misinterpret, or is there some other scenario (like try-catch)?
John Jai

Joined: May 31, 2011
Posts: 1776
UnsupportedOperationException is a RuntimeException and you are not forced to handle in the invoking method. Try to change it to Exception and compiler will ask you to handle it.
Myyron Murray Latorilla
Ranch Hand

Joined: Dec 10, 2009
Posts: 65

i think what it means is if your code for example has and explicit throw like:

then your method signature should indicate the thrown Exception like:

Hilary Mann

Joined: Jun 07, 2012
Posts: 13
Got it :

@John Jai, 'Exception' is still not working! How?

@myyron latorilla, I meant the opposite...
I agree. Here's the link:
subject: 'throws' clause specified; exception not thrown
It's not a secret anymore!