• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to throw my own exception?  RSS feed

 
Kristijan Salaj
Greenhorn
Posts: 2
Android Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

This is the code that aloow us to enter two char signs, sum their ascii values, and print the sign thats corresponding to value of the sum.

Now, I would like to make exception that is to be thrown when sum og ascii values is bigger than 255.

Here is the code:





If I enter '~' and '~' , code just sum their Ascii value and return 252!

How do I make this to work?

How to give a condition which will throw me MyException lik a regular ones?

Many thanks...

Edit by mw: Added Code Tags.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Your code seems to work fine. Note that if you change your condition to a lower sum, like 200...

if ((aA + bA) > 200)

...then it will throw the exception as expected when you input '~' and '~'.

So you just need to input two characters that sum to a quantity greater than 255, which means at least one of them will need to be outside the "standard" ASCII range (that is, greater than 127). I'm just not sure how to do that with a command prompt.
 
Kristijan Salaj
Greenhorn
Posts: 2
Android Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!