• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

What's happens when I omit the throws keyword?  RSS feed

 
Ranch Hand
Posts: 37
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

sorry for this dumb question, but I think I misunderstood something with exceptions. I thought I have to add the throws <Exceptionname> to my method signature when I want to "pass it" to the caller. However, the following code works in my Eclipse:


What did I miss here?
 
Bartender
Posts: 9494
184
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The throws keyword is used to declare checked exceptions. IllegalArgumentException is an unchecked exception, so declaring it with the throws keyword is unnecessary.

Checked exceptions are all sub-types of Exception that are not sub-types of RuntimeException.

That means that you don't have to declare Errors and RuntimeExceptions.
 
Marshal
Posts: 61766
193
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:. . . Checked exceptions are all sub-types of Exception that are not sub-types of RuntimeException. . . .

… plus Throwable; it is all in the Java┬« Language Specification (but that can be difficult to read)
 
Christian Wansart
Ranch Hand
Posts: 37
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, *that* I did not know of. Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!