This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NaturalLanguageMultiply: Exceptions

 
yen cheong
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I'm not sure whether this tutorial requires us to create our own exception or whether to use an existing one. When I run the class with a funny number, a NullPointerException is thrown. Do I use this or create my own.
Thanks for your help
Yen :confused
 
Johannes de Jong
tumbleweed
Bartender
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The aim is to catch the exception yourself.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The exception is if the string (on the command line) is not recognized and contains the message you want to show to your user."

Throw an exception with text for the user to see in the toInt() method. Have your main method catch the exception and show it to the user. Remember the text.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created my own exception class after a little nudge from Marilyn. I found that to be much more challenging and rewarding.
Matthew Phillips
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic