[1085] in java-interest

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

Re: Assertions in Java

daemon@ATHENA.MIT.EDU (Andrew Carlson)
Fri Aug 18 08:49:05 1995

Date: Fri, 18 Aug 1995 09:01:24 +0000
From: andycarlson@attmail.com (Andrew Carlson)
To: troy_hakala@stream.com (troy hakala), java-interest@java.sun.com

>>I use ASSERT a lot in C++, so think I would prefer a bit of 'syntactic
>>sugar' to make them a bit easier to write (and read) though.

>You use ASSERT?!  Why not use Exception Handling and throw an exception?
>It's cleaner and much more elegant than an assertion, IMHO.

This is getting off topic, but the answer is simple: Our code has to compile 
on 3 platforms, only one of which has a compiler which supports exceptions. 

I see no technical reason why, given a guarantee of exception support (e.g. in
java), that an assertion failure could not result in the throwing of an 
exception.

There is, however an important distinction between ASSERT and an exception 
throw: when I see an ASSERT, I know that it is essentially a debugging test, 
either of the code I am looking at or of its clients and that the test will 
not apply in the non-debug version of the code. An exception, on the oher hand
would normally be expected to apply regardless of whether it is in the debug 
or release version.

Andy.
----------------------------------------------------------------------
Andy Carlson. AT&T ISTEL                Tel: +44 1527 494358
E-Mail: andycarlson@attmail.com         Fax: +44 1527 494318
-
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