• 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Exception declaring

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code is from Kathy and Bates Java 7 guide's mock test on CD. It works fine but my question is why declaration of Exception is not required with the signature of function int getInt(String a) in Ping class at line 14??


 
author
Posts: 23877
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mian Amjad wrote:



Can you tell us what checked exception can be thrown from the parseInt() method?  Meaning what exception should be declared as throws?

Henry
 
Mian Amjad
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry, the mock test author just says note: parseInt() can throw an exception. However , by googling , I found out that parseInt() can throw NumberFormatException exception (an unchecked exception?). If unchecked then we dont have to declare? Is that where you are guiding me to?
 
Mian Amjad
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mian Amjad wrote:Henry, the mock test author just says note: parseInt() can throw an exception. However , by googling , I found out that parseInt() can throw NumberFormatException exception

 
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not required to declare exception.

Bad luck if your program throws the exception at runtime.

Your program may throw exception or not depends on the  value of args[0].

 
Henry Wong
author
Posts: 23877
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mian Amjad wrote:If unchecked then we dont have to declare? Is that where you are guiding me to?



Are you asking us to confirm that the compiler doesn't "check" an unchecked exception? ...

Henry
 
Mian Amjad
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yess Henry, I got it. ;)) Thanks.
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic