Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

double.parseDouble() - Exception

 
Niran Raj
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try {

double val = double.parseDouble("fsd");
} catch(IllegalArgumentException ex) {

}

Is it good to catch parent exception(IllegalArgumentException) of NumberFormatException ?
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion catching specific exception is better. It enables you to do different things in the catch block... like assigning a default value and move on during a number format exception or exit the method and throw exception when you get an IllegalArgument exception
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic