wood burning stoves 2.0*
The moose likes Cattle Drive and the fly likes NaturalLanguageMultiply: Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "NaturalLanguageMultiply: Exceptions" Watch "NaturalLanguageMultiply: Exceptions" New topic
Author

NaturalLanguageMultiply: Exceptions

yen cheong
Greenhorn

Joined: Aug 14, 2001
Posts: 27
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

Joined: Jan 27, 2001
Posts: 5089
The aim is to catch the exception yourself.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
"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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
I created my own exception class after a little nudge from Marilyn. I found that to be much more challenging and rewarding.
Matthew Phillips


Matthew Phillips
 
jQuery in Action, 2nd edition
 
subject: NaturalLanguageMultiply: Exceptions