[concurrency-interest] Exception throw but not speficied in the method contract of its interface

Joe Bowbeer jozart@blarg.net
Sat, 9 Oct 2004 08:27:29 -0700


On second thought, I think I may have misunderstood your question.

You're not asking about the exception declaration in Queue.add but asking 
instead about the presence of this extra exception-on-add, that could cause 
a Queue to behave badly when used as a Collection?

This is covered in Queue's class description javadoc.  See the discussion of 
offer vs add.

In practice, the exception can happen normally when trying to add to a 
bounded queue.  The javadoc recommends using the "offer" method in this 
case.


----- Original Message ----- 
From: "Joe Bowbeer" <jozart@blarg.net>
To: "Hanson Char" <hanson_char@yahoo.com>; "'Jean Morissette'" 
<jean.morissette666@videotron.ca>; 
<concurrency-interest@altair.cs.oswego.edu>
Sent: Friday, October 08, 2004 9:10 PM
Subject: Re: [concurrency-interest] Exception throw but not speficied in the 
method contract of its interface


Jean,

Adding to what Hanson wrote:

The guideline for an unchecked exception is to declare it in the javadoc, as
it is, but not in the source code (as there's no record in the classfile
anyway).

See http://java.sun.com/j2se/javadoc/writingdoccomments/#throwstag


Implementations are prone to NullPointerException and IllegalStateException
and other runtime exceptions, whereas an interface like Collection is not...


Joe.


----- Original Message ----- 
From: "Hanson Char" <hanson_char@yahoo.com>
To: "'Jean Morissette'" <jean.morissette666@videotron.ca>;
<concurrency-interest@altair.cs.oswego.edu>
Sent: Friday, October 08, 2004 5:36 PM
Subject: RE: [concurrency-interest] Exception throw but not speficied in the
method contract of its interface


In general Runtime exceptions such as IllegalStateException are considered
"unchecked" exceptions, and therefore can always be thrown without being
specified in the interface.

H

-----Original Message-----
From: concurrency-interest-admin@cs.oswego.edu
[mailto:concurrency-interest-admin@cs.oswego.edu]On Behalf Of Jean
Morissette
Sent: Saturday, 9 October 2004 8:09 AM
To: concurrency-interest@altair.cs.oswego.edu
Subject: [concurrency-interest] Exception throw but not speficied in the
method contract of its interface

Hi all, the method add(Object) of class AbstractQueue can throw an
IllegalStateException that is not specified in the contract of its
interface Collection.  Is-it normal? -Jean

_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@altair.cs.oswego.edu
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest