From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8ed8f00df051b989,start X-Google-Attributes: gid103376,public From: jehamby@lightside.com Subject: Ada exception limitations Date: 2000/02/25 Message-ID: <89738j$f27$1@nnrp1.deja.com>#1/1 X-Deja-AN: 590054973 X-Http-Proxy: 1.1 x37.deja.com:80 (Squid/1.1.22) for client 206.107.32.131 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Fri Feb 25 23:29:28 2000 GMT X-MyDeja-Info: XMYDJUIDjehamby Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt) Date: 2000-02-25T00:00:00+00:00 List-Id: 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.