• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Write My Own Exception

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic