"Everything is easy - once you know how.."
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
"Everything is easy - once you know how.."
you have to either change your reverse method to throw ArrayIndexOutOfBoundsException or change your catch statement to catch all exceptions.
[My Blog]
All roads lead to JavaRanch
Originally posted by Stuart Lord:
Many thanks for this Pete - I tried your solution and got rid of the error message. Clearly the problem lay with the scope of reverseStr - i.e.it had to be accessible outside of the if() construct.
To answer Ilja's question - the object of the exercise is to write a class that demonstrates exception handling and so if no argument was entered the length of in would be 0. This throws the ArrayIndexOutOfBoundsException exception, and so the catch should be trapping that first.
"Everything is easy - once you know how.."
"Everything is easy - once you know how.."
Originally posted by Stuart Lord:
... got rid of the error message. ...
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Note the difference between Campbell Ritchie and "Campbell Ritchie".
[Campbell@dhcppc0 disk-1]$ java trivia.StringReverserTest
Exception occurred: 0
[Campbell@dhcppc0 disk-1]$ java trivia.StringReverserTest ""
"" reversed is ""
[Campbell@dhcppc0 disk-1]$ java trivia.StringReverserTest Campbell
"Campbell" reversed is "llebpmaC"
[Campbell@dhcppc0 disk-1]$ java trivia.StringReverserTest Campbell Ritchie
"Campbell" reversed is "llebpmaC"
[Campbell@dhcppc0 disk-1]$ java trivia.StringReverserTest "Campbell Ritchie"
"Campbell Ritchie" reversed is "eihctiR llebpmaC"
Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|