File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overflow Exception

 
Kevin Simonson
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a job interview today where I was asked to write a Java method that took a String object as input and outputted the int it was equivalent to. I needed to throw an exception if the number was too big, and my interviewer indicated there is an existing exception I can use that indicates overflow. Anybody have any idea what that exception is?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use an IllegalArgumentException. It doesn't specifically indicate overflow, but it means that an argument that was passed to a method was invalid for whatever reason.

Did you have a look in the API documentation for exceptions that could match what you're looking for?
 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NumberFormatException is a subclass of IllegalArgumentException that could be used here. In fact, it [i]is[/] used by the Integer.parseInt() method, which seems to be equivalent to what the applicant is being asked to write.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java™ does not usually throw Exceptions for overflow errors. The error you are suffering is not overflow. Overflow is where you add 1 to 2147483647 and get …
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic