Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes IllegalStateException related Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "IllegalStateException related" Watch "IllegalStateException related" New topic

IllegalStateException related

Faisal Fuad
Ranch Hand

Joined: Jul 05, 2011
Posts: 83

Hi guys, was going through some common available Exceptions in Java just to learn and found this following example related to "IllegalStateException" from somewhere (sorry can't recall the source). Can any one please help me to understand here what the writer is trying to say?

The above program output is as follows:

Is there any good example(s) related to IllegalStateException?
Thank you so much...
John de Michele

Joined: Mar 09, 2009
Posts: 600

It looks like the original author is just demonstrating throwing exceptions. From the code you posted, you could replace IllegalStateException with another one, and get the same meaning.

Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

just continue the John post!.

when you throw any exception under the method its become necessary in java to have a try-catch between method call
OR throws this example under the caller method. to handle that specific exception.

a little reading may help you more.

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4351

continuing what john and muhammad said, the author is just demonstrating exception handling. i can't imagine a scenario where i would only have one line of code in a try block and all it did was throw an exception.

Visit my download page
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

It's possible the writer was trying to say something, but doing a bad job of it. Based on the presence of several misspellings, I wouldn't be surprised.
I agree. Here's the link:
subject: IllegalStateException related
It's not a secret anymore!