wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Write My Own Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Write My Own Exception" Watch "Write My Own Exception" New topic
Author

Write My Own Exception

Scott Purcell
Greenhorn

Joined: Dec 13, 2001
Posts: 1
Hello,
I failed a question on my final exam last night because I did not know how to create and use my own exception. The mission was to create a class that extends exception, then have another class use that exception. The basic problem I had to deal with was add 2 numbers, if they were greater than 100 use my exception to explain that the two numbers were greater than 100, else print that all is good. It was a simple console app, and I have been fighting it all morning and still cannot do it.
I have the following 2 classes
package finalexam;








}


Thanks for any assistance
Scott
[This message has been edited by Cindy Glass (edited December 14, 2001).]
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
You have your throw new toohigh in the wrong place.
Your check method should instead look something like this:

And take that throw statement from your catch block. Not sure why you were trying to return an int from this method if all you want to do is check to see if it is above 100 or not, and if it is, throw an exception. If anything, you MIGHT return a boolean, but I don't see that being needed.
Jason

[This message has been edited by jason adam (edited December 13, 2001).]
 
jQuery in Action, 2nd edition
 
subject: Write My Own Exception
 
Similar Threads
Cannot throw exception
why theobject is not Retrieving the current value from the file?
How do you treat a Real data type as a float
StackTrace
Problem On using wait() in THreads