File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to "throw an exception?"

 
Ashley Kin
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I wrote this code that takes values as input from a user until a negative number is entered, and then prints the average of those values, not including the negative number.
I need to figure out how to not print an average if the first number a user inputs is negative. I think I should "throw an exception," but I'm not really sure how to go about that.
Thanks!

 
Paul Clapham
Sheriff
Pie
Posts: 20164
24
MySQL Database
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really sure? Then since you want to know about exceptions, your google keywords should be "java exception tutorial".

The first link you get back should be Oracle's tutorial (have a look at the URL to make sure). Read it: Lesson: Exceptions.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic