[2552] in java-interest

home help back first fref pref prev next nref lref last post

Message not deliverable

daemon@ATHENA.MIT.EDU (Administrator)
Wed Oct 4 11:34:49 1995

Date: Wed, 04 Oct 95 03:59:57 PST
From: "Administrator" <Administrator@intuit.com>
To: java-interest@java.sun.com

java-interest-digest     Wednesday, 4 October 1995     Volume 01 : Number 205

In this issue:

  RE: IRC-Java
  Menus in Pre-Beta
  Use of Compiler and other binary classes
  Embedded Systems Programming in Java
  Re: Static class VS final class
  Re: sysadmin database-query tools need java compiler.
  Not happening
  [none]
  Classloaders again.
  jdb run command problem
  EOF
  jdb and /dev/console
  setting Insets in a Container
  Re: What pannel to use for Scrollbars 
  PreBeta release on WinNT?
  Re: Use of Compiler and other binary classes
  Re: setting Insets in a Container
  Re: Not happening  ...  it sure aint
  segmentation fault on matrix declaration
  [none]
  thread "cancels" of blocked threads
  Re: Static class VS final class
  matrix declaration caused segmentation fault problem
  persistent preferences
  Re: EOF
  Re: thread "cancels" of blocked threads
  Re: jdb run command problem
  How to replace a char in String Object
  Gateway to comp.lang.java on
  Double Buffering
  passing object
  Re: jdb run command problem
  Re: throws declataration in Java/beta

----------------------------------------------------------------------

From: Tako Schotanus <Tako.Schotanus@bouw.tno.nl>
Date: Tue, 3 Oct 1995 09:37:19 +-100
Subject: RE: IRC-Java

>-- [ From: Jayson Raymond * EMC.Ver #b.2.5.06 ] --
>
>> Does anybody know if its possible to make a irc-client as a java-applet?
>
>It's been done, check out (source included):
>
> http://www.vpro.nk/www/interaktief/java/gameserver.html

This should be: www.vpro.nl  <---

- - Tako

PS: Why is every message coming in four- or even fivefold??


------------------------------

From: lee@info.bt.co.uk (Lee Stephens)
Date: Tue, 3 Oct 1995 10:37:13 +0100
Subject: Menus in Pre-Beta

Hi,

I'm using the Pre-Beta Java package. I'm trying to use a menubar
and set of menus.

While I can attach a menubar to the frame and menus to the menubar
I don't know how to catch the menu options being selected.

I assume this is because the menu things aren't subclassed from
java.awt.Component and hence have no "action" method.

Can anybody help me please?

Lee

- ---------------------------------------------------------------
Lee M J Stephens          Tel   (01473) 641653
Intelligent Systems Unit  Int   +44 1473 641653
MLB G 1.2                 Fax   (01473) 642459
BT Laboratories           Int   +44 1473 642459
Martlesham Heath          Email lee@info.bt.co.uk
Ipswich IP5 7RE
England
- ---------------------------------------------------------------

------------------------------

From: "Mike Christiansen" <mikec@metronet.com>
Date: Tue, 3 Oct 1995 07:40:27 +0000
Subject: Use of Compiler and other binary classes

Hi.

I was wondering about the ability to utilize the binary classes whose 
sources were not included in the "binary releases". Can we subclass 
and apply the class "Compiler" without violating any license issues 
(i.e. without purchasing the $150k source license)

mike

------------------------------

From: George E Crawford <gec2@Ra.MsState.Edu>
Date: Mon, 2 Oct 1995 21:17:01 -0500
Subject: Embedded Systems Programming in Java

Does anyone know of any references to information concerning
embedded systems programming in Java? Sources that simply mention
the concept are ok, although details are a plus.

Thanks,
George Crawford III
Mississippi State University/Department of Computer Science

------------------------------

From: Ben Black <benb@velocity.com>
Date: Tue,  3 Oct 95 09:20:22 -0500
Subject: Re: Static class VS final class

>  Can someone explain the different between a static class and a final class
>for me?  Both of them cannot be subclassed and instantiated.
>
anyone who knows better, please feel free to correct me.  in objective-c  
(and, i would assume, java) a static class can only be instantiated once.   
static variables within a class (again, in objective-c) are class variables  
(shared by every instance of the class) and are not inherited.  a final class  
is one which has been frozen.  there is really no difference between a final  
class and any other class, other than the fact that subclassing it is not  
allowed.

(waiting for someone smart to enumerate my mistakes in the above paragraph)

ben

------------------------------

From: Ben Black <benb@velocity.com>
Date: Tue,  3 Oct 95 09:24:30 -0500
Subject: Re: sysadmin database-query tools need java compiler.

>However, performance is not where I'd like it to be... is there any
>word on a java-based compiler yet?  Can anyone set my expectation
>date for a release (early, mid, late 1996?)
>
there is a java compiler; it's called javac.  i think what you are asking for  
is _native_ compilers that emit native machine code rather than portable  
byte-code.  i'm waiting eagerly for the same thing (especially for Win95/NT).

ben

------------------------------

From: exceed@wwcd.com (exceed group)
Date: Tue, 3 Oct 1995 11:21:50 -0500
Subject: Not happening

Hi

Nothing but red boxes where the applets would go.

All seems to check out fine.
Guess not...

Any help appreciated.

solaris 2.4     sun box   

------------------------------

From: gabe@ucsd.edu (Gabriel Lawrence)
Date: Tue, 3 Oct 1995 08:51:23 -0800
Subject: [none]

>> Then, an hour later, another applet "SayName" is run, which looks up
>> your name and speaks it out loud. How is this information to be passed
>> (and stored) between applets?
>>
>> Once possibility would be to store the relevant information in
>> environment variables. Is this supported by Java? I noticed that
>> getenv() (in java.lang.System) has been marked obsolete.
>>
>> Or do we need to save the information to a local file? Or is there
>> some other preferred way to handle this type of communication?
>
>Right now applets can comminicate among each other as long as they
>are on the same page. There is no way an applet can store persistent
>information. There are some security considerations, but this may
>be something we could add later.
>

Why not create persistent information server? The first applet can store
its information on the server, and as part of the start up of your applet
it could query a server for its preferences. All you need to do is have
some kind of identifier that will allow you to pick preferences uniquely
for each user on a machine.


- -Gabe

- -----------------------------------------------------------------------
                Scripps Institution of Oceanography
                          UC San Diego
                        Wrk: 619.534.8484
- -----------------------------------------------------------------------
Hme: 619.455.6506                    http://sio.ucsd.edu/~gabe/



------------------------------

From: chanda@PRPA.Philips.COM (Chanda Dharap)
Date: Tue, 3 Oct 95 09:50:01 PDT
Subject: Classloaders again.

HI ..

After going through Chuck's detailed response i thought i could
manage.

... however....

If anyone has experience with definig their own ClassLoaders can they
shed some light ? I probably should directly ask one of the java
guru's .. but i'm beginning to feel guilty !!!

the loadClass I defined seems to read all the correct bytes as they
are equal to the size of the .class file

Its not able to "defineClass()" as this is what happens:

- -------------------------------------------------------------
In loadClass: before loading from InputSTream
 
In reading from file
 

bytes length 4096 Total 0 n is 478
 
before defineClass() 
 
java.lang.IOException java.lang.Object.class
        at java.io.FileInputStream.<init>(FileInputStream.java)
        at FileClassLoader.loadClass(FileClassLoader.java:73)
        at FileClassLoader.loadClass(FileClassLoader.java:42)
        at FileClassLoader.loadClass(FileClassLoader.java:76)
        at FileClassLoader.main(FileClassLoader.java:98)
> ls -l foo.class
- -rw-r-----  1 chanda        478 Oct  3 09:37 foo.class
- ---------------------------------------------------------------

If anyone thinks they can do better with reading my code I'll mail it.

any help appreciated.. 

- - chanda

------------------------------

From: Hui Zhao Wang <huizhao@krypton.stanford.edu>
Date: Tue, 3 Oct 1995 10:55:31 -0700 (PDT)
Subject: jdb run command problem

Hi,

  When I using jdb, try to specify arguments in 'run' command, like this:

'run <arg1> <arg2>'

  It alwayse failed, it says 'arg1 failed' which doesn't make sense, since it 
is just an argument. By the way, the program I debugged is a working one.

  I seems to me jdb run command don't like arguments. Is there any work around?

thx,
huizhao

------------------------------

From: "Elliotte Rusty Harold" <Elliotte@blackstar.com>
Date: Tue, 3 Oct 1995 14:05:03 EST
Subject: EOF

Does java have any equivalent to C's EOF?  i.e. in C it's quite 
common to do something like

while (fgets != EOF) {

What I'd like to do in java is 

    DataInputStream theCharacters = new DataInputStream(System.in);
    while ((thisChar = theCharacters.readChar()) != EOF) { 

However although the term "EOF" shows up occasionally in the java 
docs it's not precisely defined.  


- --
Elliotte Rusty Harold    Black Star Publishing Co., Inc.
elliotte@blackstar.com   116 East 27th Street
elharo@escape.com        NY NY 10016

------------------------------

From: Larry Reu <larryr@CyberGate.COM>
Date: Tue, 3 Oct 1995 11:36:02 -0700 (PDT)
Subject: jdb and /dev/console

Is there a fix or workaround for jdb's insistence on opening
/dev/console.  I'm on a multi-user sparc system and don't 
have access to the console.  I'd really like to use jdb!

.......larry

------------------------------

From: Brad Paley <paley_brad@jpmorgan.com>
Date: Tue, 3 Oct 1995 14:54:40 -0400
Subject: setting Insets in a Container

Hope this isn't a dumb question; I'm just starting.

I can't see any way to set Inset values in Containers; can I?

Brad

------------------------------

From: Bindu Wavell (RUFUS) <wavell@taussky.cs.colorado.edu>
Date: Tue, 03 Oct 1995 13:34:16 -0600
Subject: Re: What pannel to use for Scrollbars 

In message:  <9510031056.AA21961@elao.enst.fr>
             dufourd@enst.enst.fr writes:
> My experience is that there is a bug somewhere (maybe in the compiler)
>which consequence is that the layout manager gets null instead of the string
>given as first parameter of add. So BorderLayout is out.
>One possibility is to use the layout manager I posted recently, 
RelativeLayout.
>It does not exercize the bug in question. Another possibility is to
>wait for the fix.

Hmmm.. I'm not having problems with BorderLayout, it and the CardTest demo
seem to work just fine.  I will however take a look at your RelativeLayout
LayoutManager, thanks for the tip.

> RelativeLayout can be found at :
>http://www-elec.enst.fr/java/mos-beta/RelativeLayout.java
>http://www-elec.enst.fr/java/mos-beta/RelativePlacement.java
>
> An example of use is:
>http://www-elec.enst.fr/java/mos-beta/test.html

- -- Bindu

------------------------------

From: Bill Tschumy <bill@otherwise.com>
Date: Tue,  3 Oct 95 14:51:01 -0500
Subject: PreBeta release on WinNT?

Does anyone have an approximate time frame for the PreBeta release on WinNT?

- ---
Bill Tschumy
Otherwise
bill@otherwise.com (NeXTmail and MIME accepted)


------------------------------

From: Thomas.Ball@Eng.Sun.COM (Thomas Ball)
Date: Tue, 3 Oct 1995 13:22:54 -0700
Subject: Re: Use of Compiler and other binary classes

>  I was wondering about the ability to utilize the binary classes whose 
>  sources were not included in the "binary releases". Can we subclass 
>  and apply the class "Compiler" without violating any license issues 
>  (i.e. without purchasing the $150k source license)

Yes, but those classes may not be present on all "Java-compatible"
systems.  If that level of compatibility isn't required by your app, go
for it.  You just shouldn't redistribute those class files as part of
your product -- have your clients get their own copy in some legal
fashion.  For example, someone with a Netscape 2.0 browser would need
to pick up a copy of Sun's release for those missing files.  The same
works in reverse if Netscape develops their own specialized classes.

Tom Ball
Java Products Group

------------------------------

From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
Date: Tue, 3 Oct 1995 13:04:55 -0700
Subject: Re: setting Insets in a Container

Hi Brad,

> I can't see any way to set Inset values in Containers; can I?

You can specify the insets by overriding the insets() method:

 public Insets insets() {
     return new Insets(top, left, bottom, right);
 }
  
Have fun,

 Arthur van Hoff
 

------------------------------

From: dthomas@engr.soltech.com (Douglas Thomas)
Date: Tue, 3 Oct 1995 17:39:09 -0400
Subject: Re: Not happening  ...  it sure aint

> Hi
> 
> Nothing but red boxes where the applets would go.
> 
> All seems to check out fine.
> Guess not...
> 
> Any help appreciated.
> 
> solaris 2.4     sun box   

hi

nothing but blank spaces where the help would go.

all would be fine if you gave us some more info to go on.
but guess not...

more information appreciated.

also solaris 2.4   sun box
- -- 

        _/                    _/
        _/                    _/
        _/                    _/
        _/                    _/
  _/ _/ _/    _/  _/    _/ _/ _/ _/ _/
_/      _/  _/      _/        _/ 
_/      _/  _/                _/
_/      _/  _/                _/
_/      _/  _/      _/        _/
  _/  _/      _/  _/          _/

     
'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
douglas c thomas
 
soltech systems corporation
1180 sam rittenberg blvd.   phone: 803-556-2500
suite 310     fax:   803-556-2596 
charleston, sc 29407    email: dthomas@soltech.com 

'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'

------------------------------

From: Edith Au <edith@pencom.com>
Date: Tue, 3 Oct 1995 17:55:21 -0400 (EDT)
Subject: segmentation fault on matrix declaration

Hi,

  I declared a matrix and get segmentation fault when I tried the compile it.

  class matrix
  {

  int grid[][] = new int[4][4];

  }

  I got a bus error and then segmentation fault.  But I could successfully
compiled in Alpha3.  Any clue?

Cheers,
Edith
 


------------------------------

From: "Ming Sheng Wang -- Your friend." <bd27671@bingsuns.cc.binghamton.edu>
Date: Tue, 3 Oct 1995 18:17:12 -0400 (EDT)
Subject: [none]

unsuscribe

------------------------------

From: caveh@updoc-39.Eng.Sun.COM (Caveh Jalali)
Date: Tue, 3 Oct 1995 15:23:21 -0700
Subject: thread "cancels" of blocked threads

how do you cancel a thread?  i'm currently using the Thread.stop()
method, but the target thread is blocked on a Socket.read() and
aparently can't be cancelled at that point.  closing the Socket also
doesn't seem to unblock the Socket.read().

- -- 
00c

------------------------------

From: avh@jakarta.Eng.Sun.COM (Arthur van Hoff)
Date: Tue, 3 Oct 1995 09:18:50 -0700
Subject: Re: Static class VS final class

Hi Edith,

>   Can someone explain the different between a static class and a final class
> for me?  Both of them cannot be subclassed and instantiated.

I'm not sure what a static class"` is, there is no such concept in Java.
Do you perhaps mean abstract class? An abstract class can't be instanciated
directly, it needs to be subclassed. A final class is a class that can't
be subclassed, but it can be instanciated.

Have fun,

 Arthur van Hoff
 

------------------------------

From: Edith Au <edith@pencom.com>
Date: Tue, 3 Oct 1995 19:01:26 -0400 (EDT)
Subject: matrix declaration caused segmentation fault problem

Hi,

   I posted a question before about declaration of a 2 dimensional array
caused segmentation fault.  I found out what the problem is.  I had
too many windows open and low in memory.  The preBeta version requires
more memory to compile than the Alpha version.

Cheers,
Edith


------------------------------

From: Ben Black <benb@velocity.com>
Date: Tue,  3 Oct 95 18:07:52 -0500
Subject: persistent preferences

>Why not create persistent information server? The first applet can store
>its information on the server, and as part of the start up of your applet
>it could query a server for its preferences. All you need to do is have
>some kind of identifier that will allow you to pick preferences uniquely
>for each user on a machine.
>
>
>-Gabe
>

rush over to the netscape website and read about their persistent cookie  
ideas.  it isn't the greatest solution, but it is really simple, and would  
solve this problem.


ben

------------------------------

From: cmcmanis@scndprsn.Eng.Sun.COM (Chuck McManis)
Date: Tue, 3 Oct 1995 11:54:41 -0700
Subject: Re: EOF

>while (fgets != EOF) {
>
>What I'd like to do in java is 
>
>    DataInputStream theCharacters = new DataInputStream(System.in);
>    while ((thisChar = theCharacters.readChar()) != EOF) { 
>
>However although the term "EOF" shows up occasionally in the java 
>docs it's not precisely defined.  

For DataInputStream in beta there is EOFException. You could write it
like this:

 try {
     while (1) {
  thisChar = theCharacters.readChar();
  // process some character
     }
 } catch (EOFException e) {
    // all done.
 }

for non-DataInputStreams you are still stuck doing:
 while (res = foo.read()) != -1) ...

- --Chuck

------------------------------

From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
Date: Tue, 3 Oct 1995 16:34:18 -0700
Subject: Re: thread "cancels" of blocked threads

Hi,

> how do you cancel a thread?  i'm currently using the Thread.stop()
> method, but the target thread is blocked on a Socket.read() and
> aparently can't be cancelled at that point.  closing the Socket also
> doesn't seem to unblock the Socket.read().

This is a problem that we'll be solving in upcoming releases. The idea
is that you should be able to break out of a blocking call by interrupting
a thread using Thread.interrupt(). The blocking call will be terminated
with an InterruptedException and a flag in the thread and Thread.interrupted() 
will be true. The thread should then be given a change to cooperatively
terminate. If that fails you can try Thread.stop() which will throw
a ThreadDeath exception.

We unfortunately didn't have time to finish this before the release went
out.

Have fun,

 Arthur van Hoff

------------------------------

From: Hui Zhao Wang <huizhao@krypton.stanford.edu>
Date: Tue, 3 Oct 1995 16:32:34 -0700 (PDT)
Subject: Re: jdb run command problem

>The run command requires that you specify the class to run, followed by
>any optional arguments.  It tried to run the class "arg1", and reported
>its failure.  The reason for requiring the class name is that "in theory"
>you can run multiple classes concurrently, each in their own threadgroup.
>I say "in theory" because I haven't had time to test this much yet.
>
>Note that if you specify the arguments on the command line (as in
>"jdb MyClass arg1 arg2"), those arguments are saved so that just typing
>"run" is sufficient to start your class.
>
>Tom Ball
>Java Products Group
>

Excellent! Thank Tom. you guys might want alter the jdb help text, since it 
display as 'run <args>', if change to 'run class_id <args>', will make much 
sense.

huizhao



------------------------------

From: Hui Zhao Wang <huizhao@krypton.stanford.edu>
Date: Tue, 3 Oct 1995 16:38:22 -0700 (PDT)
Subject: How to replace a char in String Object

Hi,

   I am struggling to figure out how to replace a certain char by another, say,
I want to get rid of newline char from a String object. I tried:

          str2 = str1.replace('\n', '\000');

   The newline char is still in str2; then I tried:

          str2 = str1.replace('\x0a', '\x00');

   the compiler complains '\x0a', '\x00' they are invalid escape character.

   I am not sure whether this is something to do with java char is 16bit or 
not.

   Sorry in advance if this is an answered question.

huizhao







------------------------------

From: lindholm@scndprsn.Eng.Sun.COM (Tim Lindholm)
Date: Mon, 2 Oct 1995 16:35:51 -0700
Subject: Gateway to comp.lang.java on

Dear readers of java-interest and java-porting,

All mail to java-interest@java.sun.com, java-porting@java.sun.com and
java-announce@java.sun.com is now being automatically forwarded to the
new comp.lang.java news group. Mail to hotjava-interest@java.sun.com
does not really belong in comp.lang.java according to its charter, so we
will be forwarding it to alt.www.hotjava soon.  For the time being you
will be able to tell messages that have been forwarded from the mailing
lists by their reassuring

  Note to Sun employees: this is an EXTERNAL mailing list!

footers, although these will probably be stripped away in the future.

Please try getting your Java fix by reading comp.lang.java rather than
the mailing lists.  This is especially true for those of you who don't
require quick turnaround, like -digest readers.  If the mailing list
works for you, we *strongly* urge that you *unsubscribe* from the
mailing lists.  Doing so will help to reduce the load on java.sun.com
and its line out to the world, and improve service for everyone.

To unsubscribe from one of the mailing lists, say java-interest, you'd
normally mail majordomo@java.sun.com a message with a line like the
following in the body:

   unsubscribe java-interest

You can also unsubscribe a specific address, e.g.

   unsubscribe java-interest me@home.org

If you don't know what address you're subscribed under, you can find out
by mailing majordomo@java.sun.com a message of the form

   which <substr>

which will cause a list of all addresses containing the substring <substr>
to be mailed back to you.

The important points, again: try comp.lang.java, and if that works for
you, unsubscribe from the mailing lists!

- -- Tim

------------------------------

From: "C. Jones" <cvj@u.washington.edu>
Date: Tue, 3 Oct 1995 18:57:55 -0700 (PDT)
Subject: Double Buffering

Dear Folks

I wrote a java application that puts up a gif file and then allows the user to draw some lines on top of it.  I implemented double buffering as suggested in the Java documentation, but the image still flashes as the user draws.

Any suggestions?

NotesS:
I developed the application under Windows NT using the 1.3 alpha release.
The page is located at http://weber.u.washington.edu/~cvj/tsp.html.

I'm a newbie, so if this is not the appropriate forum, or the answer
exists in an FAQ, please forgive me (and direct me to the location of
the answer).

Thanks,
Chris Jones
U. Washington

------------------------------

From: Larry Liang <lliang@bellcore.com>
Date: Tue, 3 Oct 1995 22:27:14 -0400
Subject: passing object

Is there a generic way to pass objects on a stream? The stream API
seems only support the builtin types. 

Larry

------------------------------

From: Thomas.Ball@Eng.Sun.COM (Thomas Ball)
Date: Tue, 3 Oct 1995 12:14:13 -0700
Subject: Re: jdb run command problem

The run command requires that you specify the class to run, followed by
any optional arguments.  It tried to run the class "arg1", and reported
its failure.  The reason for requiring the class name is that "in theory"
you can run multiple classes concurrently, each in their own threadgroup.
I say "in theory" because I haven't had time to test this much yet.

Note that if you specify the arguments on the command line (as in
"jdb MyClass arg1 arg2"), those arguments are saved so that just typing
"run" is sufficient to start your class.

Tom Ball
Java Products Group

>  From daemon@java  Tue Oct  3 11:20:57 1995
>  Subject: jdb run command problem
>  To: java-interest@java
>  Cc: huizhao@krypton.stanford.edu
>  Mime-Version: 1.0
>  X-Info: To unsubscribe, send 'unsubscribe' to java-interest-request@java.sun.com
>  
>  Hi,
>  
>    When I using jdb, try to specify arguments in 'run' command, like this:
>  
>  'run <arg1> <arg2>'
>  
>    It alwayse failed, it says 'arg1 failed' which doesn't make sense, since it 
>  is just an argument. By the way, the program I debugged is a working one.
>  
>    I seems to me jdb run command don't like arguments. Is there any work around?
>  
>  thx,
>  huizhao
>  -
>  Note to Sun employees: this is an EXTERNAL mailing list!
>  Info: send 'help' to java-interest-request@java.sun.com
>  

------------------------------

From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
Date: Mon, 2 Oct 1995 14:46:48 -0700
Subject: Re: throws declataration in Java/beta

> > > >Only forseen exceptions are generally required to be declared (and
> > > >therefore need to be caught or explicitly passed on).  Exceptions which
> > > >are subclasses of RuntimeException or Error - which are not generally
> > > >part of the API of a given method - don't have to be declared. 
> 
> Does this mean that all exceptions generated by subclasses should be derived
> from RuntimeException or Error? 

It depends on the API that you are overriding.  If you need to indicate
some kind of programming bug (i.e. equivalent to the caller handing you
a null pointer where you absolutely needed a real object), then throw
something like a NullPointerException, which is a subclass of RuntimeException.
(Or in this case you could just use the pointer and let the runtime throw
the NullPointerException for you).

Cases such as informing the caller about some asynchronous condition
which occured which prevents his *properly formatted* requested action
from being completed - such as a file system running out of space, or a
long wait being interrupted, then hopefully the API that you defined,
or that you are overriding, has been declared to possibly throw an
appropriate exception.  The declaration of this exception is roughly
analogous to declaring a procedure to return a status code instead of
declaring it to return void, except that the exception operates
differently than a return code (i.e. it is thrown and caught rather
than assigned to a variable and tested).

If you are overriding an existing API which did not declare an
exception for you, then this is a problem in the design of that API
similar to what might have happened in C where you are implementing an
API that is defined to return void and suddenly you need to return a
status code - i.e. you are out of luck and the API was defined
inappropriately.  On the other hand, perhaps the person who designed
that API felt that the proper action for the subclass to take when it
finds a problem is to perform some appropriate default action (such as
ignoring the request to delete something which doesn't exist or setting
a value to a default when the requested value is out of range) instead
of bothering the caller with a thrown exception.

> > > >Exceptions such as IOException, which are part of the natural working
> > > >domain of many methods, must be declared where they can occur so that
> > > >callers of that method are aware that the indicated exception is a
> > > >possible result of calling the method. 
> 
> This seems like splitting hairs.  Why isn't an IOException a RuntimeException
> or an Error? 

Because it doesn't represent a programming problem that was detected by
the runtime or an inappropriate use of an API.  It represents useful
information about the operation of a legally specified request that the
caller may have had no control over and that the caller needs to be
informed about - i.e. the filesystem is now full, or the remote end has
closed the connection, or the access priveleges don't allow this action.

> > > It seems to me that this reasoning has a flaw. It assumes that the base
> > > class designer can forsee all possible algorithms needed by all possible
> > > subclasses, and include the necessary exception declarations to cover
> > > them.  
> 
> I also feel this way.  The "subclasses of RuntimeException or Error" seems to
> eliminate this concern, but only because it means that in fact any subclass
> can throw "any" exception, that it invents anyway. 

Any interface can be abused.  If you are defining some kind of general
purpose API that will be implemented by an arbitrary agent, then try to
predict whether or not there will be such agents that may need to indicate
a preventive condition that will be useful for the caller to know about
and plan for the necessary exceptions that these agents may wish to throw.

For instance InputStream is an abstract class, it does not implement a
stream, it merely specifies the API for one.  Since it does not implement
a stream, its read() method doesn't have any exceptions to throw, but
a subclasser may need to throw some kind of exception indicating some
problem with the IO channel which prevents reading.  So, it declares that
it throws IOException.  Now any subclass of InputStream can throw any
flavor of IOException that it wishes - and can even invent its own subclass
of IOException to be distinguishable if such information is useful.

Another example is the toString() method of Object.  It does not
declare any exceptions because it is not useful to have a toString()
method on an object that can throw an exception - the resulting
try/catch insanity on every string construction would be a nightmare.
So, it does not declare any exceptions and callers can rest assured
that they can use it without any dire consequences.  If a subclass
somehow finds a problem in constructing a string representation of
itself it can choose to return an empty string (or even
"myClass[oops]"), or if the problem is something catastrophic such as a
memory failure, then it can throw an OutOfMemoryException (a runtime
exception) or something like that, but callers should not feel as if
there is some reason to doubt the completability of Object.toString()
so no exceptions are declared.

> > Can you give a concrete example?  If a subclasser wants to throw a new kind
> > of exception, then he is most likely trying to fit a round peg into a
> > square hole... 
> 
> OK: ScrollableItemNotFound exception for a derived button to be used in a
> floating "remote control" or palette, which causes the top-most window's
> scrollable item to scroll downwards.   

Why not just define the operation as a Noop if there is no scrollable
item?  On the other hand, since the method from which you return this
would be one that we haven't defined - then you are the one defining
the method, so go ahead and declare it as returning ScrollableItemNotFound.

> It seems that the most useful concept behind exceptions is not that there is
> a fixed set, but that they can be used to handle rare failures, so the code
> is more readable: the "straight" code deals with the nominal case, and the
> "catch" code deals with all sorts of possible exceptions. 

Exactly.  What point are you trying to make here?  We don't have a fixed
set of exceptions, just a predefined contract on each method *we* have
defined in *our* APIs that *we* want to guarantee for people using *our*
APIs.  If you are trying to override one of our methods and you don't like
our choice of exceptions, then perhaps you don't understand the API contract
we have defined, or perhaps you just don't like it, but it is the contract
we wanted.  If you are creating a brand new method, then knock yourself
out allowing "throws Exception" and see how useful it is to try to deal
with that method as a caller.  At some point, you have to drive a stake
in the ground otherwise any method anywhere can throw any exception, even
if the caller did everything he thought he was supposed to do correctly
and the resulting paranoia ends up being useless.

    ...jim

------------------------------

End of java-interest-digest V1 #205
***********************************


Received: from gw.intuit.com by intugate.intuit.com (SMTPLINK V2.10.02)
From owner-java-interest-digest@java.sun.com
X-Envelope-From: owner-java-interest-digest@java.sun.com
Received: by gw.intuit.com (4.1/SMI-4.1)
    id AA08562; Wed, 4 Oct 95 03:36:40 PDT
Errors-To: owner-java-interest-digest@java.sun.com
Received: from java.sun.com(206.26.48.100) by gw.intuit.com via smap (V1.3)
    id sma008552; Wed Oct  4 03:36:35 1995
Received: (from majordom@localhost) by java.sun.com (8.6.12/8.6.12) id TAA27058 for java-interest-digest-outgoing; Tue, 3 Oct 1995 19:45:33 -0700
Date: Tue, 3 Oct 1995 19:45:33 -0700
Message-Id: <199510040245.TAA27058@java.sun.com>
From: owner-java-interest-digest@java.sun.com
To: java-interest-digest@java.sun.com
Subject:   java-interest-digest V1 #205
Reply-To: java-interest@java.sun.com
Errors-To: owner-java-interest-digest@java.sun.com
Precedence: bulk
X-Info: To unsubscribe, send 'unsubscribe' to java-interest-digest-request@java.sun.com

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post