Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalStateException related

 
Faisal Fuad
Ranch Hand
Posts: 83
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Faisal,

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.

John.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Randall Twede
Ranch Hand
Posts: 4385
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic