Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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?
 
Saloon Keeper
Posts: 9118
172
  • 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: 59681
187
  • 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!