• 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

how to throw my own exception?

 
Greenhorn
Posts: 2
Android Firefox Browser Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot!
 
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic