comp.lang.ada
 help / color / mirror / Atom feed
* Ada exception limitations
@ 2000-02-25  0:00 jehamby
  2000-02-25  0:00 ` Stanley R. Allen
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: jehamby @ 2000-02-25  0:00 UTC (permalink / raw)


Recently I've been revisiting Ada after a long absence.  My main gripe
with C++ is its cryptic syntax and excessive complexity.  I really like
Java, the language, but compilers from Java to native code are
immature, JIT interpreters are still too slow for some tasks, and I'm
not too fond of the class library or the difficulty of interfacing
native code to Java through JNI.

Anyway, Ada 95 seems to be the answer to many of my complaints, yet one
thing I dislike is that I've noticed some weaknesses in its exception
handling capabilities compared to what I've grown used to with Java.
For example, a current project I've written in Java (a database server)
has an exception hierarchy like this:

public class ABCException extends java.lang.Exception {
    private int errCode;
    public ABCException() {
	super();
	errCode = 0;
    }
    public ABCException(int errCode, String s) {
	super(s);
	this.errCode = errCode;
    }
    public int getErrorCode() {
	return errCode;
    }
    public String toString() {
	return "E" + errCode + ": " + getMessage();
    }
}

Then I have subclasses of ABCException for different types of
exceptions that can be thrown inside the code.  For example,
ABCUserException, ABCInternalException, etc.  Within a subclass, the
particular exception is defined by a unique error code, which is sent
to the client, who can look it up and print an ASCII error message to
the user.  I have a logging function on the server which stores the
error message, along with the client that generated it, as well.

I'm not planning to port this to Ada, but if I were to, I think the
mapping of my exception classes to Ada exceptions would be the biggest
weakness.  In particular, I see two areas where Java (and C++) beat Ada
for exception handling:

#1:  No hierarchical exceptions.  AFAIK, I can't declare an Ada
exception as a child of another exception, and then catch both
exceptions with a single 'when' clause.  I wouldn't want to collapse
all of my custom exceptions down to a single Ada exception, but neither
putting a long list of when clauses into every exception handler, nor
using 'when others' for everything, appeals to me.

#2:  No ability to associate user data with exceptions.  I know it's
possible to raise an exception with an associated string message, and I
could use this to pass the error number as a string, but this seems
kludgy.

If I'm wrong about either of those counts, I'd really like to know.  I
suppose, had I originally written this program in Ada, I probably would
have done things differently, perhaps using a single exception type for
the entire program, and storing the particular error code in a thread-
local variable so that it could be sent to the client.  However, I
rather prefer the way it ended up in Java.  My question is:  have any
attempts been made to update the standard to make Ada exception
handling more like C++ or Java?  Does GNAT offer any extended
capabilities in this area?

Thanks,
-Jake


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-02-27  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-25  0:00 Ada exception limitations jehamby
2000-02-25  0:00 ` Stanley R. Allen
2000-02-26  0:00 ` Ehud Lamm
2000-02-26  0:00 ` James S. Rogers
2000-02-26  0:00 ` Laurent Guerby
2000-02-27  0:00   ` jehamby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox