• Post Reply Bookmark Topic Watch Topic
  • New Topic

What handling the exception and declaring the same exception in throws clause achieve?  RSS feed

 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was giving a quick skim to some tutorials on the internet where I have found the exception that is handled is also declared in the throws clause of the method wrapping the try-catch block.

For a code representation consider the following:



I'm failing to get the big picture on this occasion. Would anyone help me understand the nuanced use of exception employed here or point me in the right direction?
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What tutorial? Please QuoteYourSources (<-- click)

The example you show is pretty silly. Declaring your method to throw some exception that your code will never throw does not make sense. Unless of course "....TODO handle exception" includes explicitly throwing that exception.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disregard the above; I realize it does not make any sense. I need to brush up on exceptions.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!