File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "NaturalLanguageMultiply: Exceptions" Watch "NaturalLanguageMultiply: Exceptions" New topic

NaturalLanguageMultiply: Exceptions

yen cheong

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

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

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

"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
I agree. Here's the link:
subject: NaturalLanguageMultiply: Exceptions
It's not a secret anymore!