IllegalStateException?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

IllegalStateException?

 
0
  #1
Apr 19th, 2005
I've looked and looked for some good material on this exception, but I can't find anything helpful. I just don't understand it. It's suppose to be caught or thrown whenever a method is called when not suppose to be...But won't other exceptions be caught or thrown in it's place? If you have any comments or anything to say, please post!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 44
Reputation: starsunited is an unknown quantity at this point 
Solved Threads: 1
starsunited's Avatar
starsunited starsunited is offline Offline
Light Poster

Re: IllegalStateException?

 
0
  #2
Apr 20th, 2005
but then u never catch this expection in the first place. if you want to catch all expections can try using this

  1. try
  2. {}
  3. catch(Exception e)
  4. {
  5. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: IllegalStateException?

 
0
  #3
Apr 20th, 2005
I know that, but I just don't undestand this exception. What is it for? I mean, when is a method called, but not suppose to be called?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: IllegalStateException?

 
0
  #4
Apr 20th, 2005
Think of calling a method to do a database query on a database that is closed.
Or calling a read method on a stream that's past the end of the data.
Or calling write methods on a readonly file.

Note that these won't throw IllegalStateException in Java but they could (they throw something more specific).

In general it's there to indicate you're trying to do something with an object that at that moment isn't possible to do with it.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: IllegalStateException?

 
0
  #5
Apr 20th, 2005
Originally Posted by jwenting
Note that these won't throw IllegalStateException in Java but they could (they throw something more specific).
This is what I was looking for. I was thinking this was the case,but wasn't sure. So I guess this means that this exception would have to be pretty high on the exception hierarchy?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: IllegalStateException?

 
0
  #6
Apr 20th, 2005
It is. But remember File et.al. typically throw IOExceptions which don't derive from IllegalStateException.

IllegalStateException is a RuntimeException, which is why you'll find few cases of it being explicitly caught (usually these are used to indicate programming errors rather than runtime problems, despite what their name suggests) while IOException is a regular Exception which requires catching at some point.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: IllegalStateException?

 
0
  #7
Apr 20th, 2005
So would it be called bad practice to throw one of these? I mean, couldn't it be almot considered as doing a catch-all-throw clause like throws Exception?

Have you ever seen this exception used before?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC