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

David Holmes dholmes@dltech.com.au
Mon, 11 Oct 2004 12:27:11 +1000


This is a multi-part message in MIME format.

------=_NextPart_000_0094_01C4AF8D.A1F7AEF0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Yes - implicitly, it must be an unchecked exception. The language rules
prevent it from being a checked exception.

David Holmes
  -----Original Message-----
  From: concurrency-interest-admin@cs.oswego.edu
[mailto:concurrency-interest-admin@cs.oswego.edu]On Behalf Of Hanson Char
  Sent: Monday, 11 October 2004 12:13 PM
  To: concurrency-interest@altair.cs.oswego.edu
  Subject: RE: [concurrency-interest] Exception throw but not speficied in
the method contract of its interface


  >...the supertype explicitly allows for an
  >exception to be thrown, it just doesn't specify exactly what kind.

  Doesn't the contract in such case imply a kind of Runtime (ie unchecked)
exception  to be thrown ?

  H

  David Holmes <dholmes@dltech.com.au> wrote:
    > Jean Morissette writes:
    >
    > 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?

    If you look at the specification for Collection.add it states:

    "If a collection refuses to add a particular element for any reason
other
    than that it already contains the element, it must throw an exception
    (rather than returning false). "

    And this is exactly what AbstractQueue does - and what AbstractQueue
    documents that it does.

    While unchecked exceptions can always be thrown by an implementation,
that
    doesn't give an implementation the right to throw any unchecked
exception
    under any circumstance - proper subtyping requires adherence to the
contract
    of the supertype. But in this case the supertype explicitly ! allows for
an
    exception to be thrown, it just doesn't specify exactly what kind.

    David Holmes

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



----------------------------------------------------------------------------
--
  Do you Yahoo!?
  vote.yahoo.com - Register online to vote today!

------=_NextPart_000_0094_01C4AF8D.A1F7AEF0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2800.1458" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D096252602-11102004><FONT face=3D"Courier New" =
color=3D#0000ff=20
size=3D2>Yes - implicitly, it must be an unchecked exception. The =
language rules=20
prevent it from being a checked exception.</FONT></SPAN></DIV>
<DIV><SPAN class=3D096252602-11102004><FONT face=3D"Courier New" =
color=3D#0000ff=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D096252602-11102004><FONT face=3D"Courier New" =
color=3D#0000ff=20
size=3D2>David Holmes</FONT></SPAN></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px =
solid">
  <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
  size=3D2>-----Original Message-----<BR><B>From:</B>=20
  concurrency-interest-admin@cs.oswego.edu=20
  [mailto:concurrency-interest-admin@cs.oswego.edu]<B>On Behalf Of =
</B>Hanson=20
  Char<BR><B>Sent:</B> Monday, 11 October 2004 12:13 PM<BR><B>To:</B>=20
  concurrency-interest@altair.cs.oswego.edu<BR><B>Subject:</B> RE:=20
  [concurrency-interest] Exception throw but not speficied in the method =

  contract of its interface<BR><BR></FONT></DIV>
  <DIV>&gt;...the supertype explicitly allows for an</DIV>
  <DIV>&gt;exception to be thrown, it just doesn't specify exactly what=20
  kind.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>Doesn't the contract in such case imply a kind of Runtime (ie =
unchecked)=20
  exception&nbsp; to be thrown ?<BR></DIV>
  <DIV>H<BR><BR><B><I>David Holmes &lt;dholmes@dltech.com.au&gt;</I></B> =

  wrote:</DIV>
  <BLOCKQUOTE class=3Dreplbq=20
  style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px =
solid">&gt;=20
    Jean Morissette writes:<BR>&gt;<BR>&gt; the method add(Object) of =
class=20
    AbstractQueue can throw an<BR>&gt; IllegalStateException that is not =

    specified in the contract of its<BR>&gt; interface Collection. Is-it =

    normal?<BR><BR>If you look at the specification for Collection.add =
it=20
    states:<BR><BR>"If a collection refuses to add a particular element =
for any=20
    reason other<BR>than that it already contains the element, it must =
throw an=20
    exception<BR>(rather than returning false). "<BR><BR>And this is =
exactly=20
    what AbstractQueue does - and what AbstractQueue<BR>documents that =
it=20
    does.<BR><BR>While unchecked exceptions can always be thrown by an=20
    implementation, that<BR>doesn't give an implementation the right to =
throw=20
    any unchecked exception<BR>under any circumstance - proper subtyping =

    requires adherence to the contract<BR>of the supertype. But in this =
case the=20
    supertype explicitly ! allows for an<BR>exception to be thrown, it =
just=20
    doesn't specify exactly what kind.<BR><BR>David=20
    =
Holmes<BR><BR>_______________________________________________<BR>Concurre=
ncy-interest=20
    mailing=20
    =
list<BR>Concurrency-interest@altair.cs.oswego.edu<BR>http://altair.cs.osw=
ego.edu/mailman/listinfo/concurrency-interest<BR></BLOCKQUOTE>
  <P>
  <HR SIZE=3D1>
  Do you Yahoo!?<BR><A href=3D"http://vote.yahoo.com">vote.yahoo.com</A> =
-=20
  Register online to vote today!</BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0094_01C4AF8D.A1F7AEF0--