[comp.lang.c] exception handling in C

herlihy@crlmh.crl.dec.com (Maurice Herlihy) (03/07/90)

I'm soliciting information on (1) exception handling packages for C, and
(2) what people consider to be reasonable conventions for dealing with
exceptions and errors in standard C.

daves@hpopd.HP.COM (Dave Straker) (03/07/90)

Mmm. This sounds interesting. If there's any mail flying around, could
you copy me too please?

Thanks muchly,

Dave Straker

grano@cs.Helsinki.FI (Kari Gran|) (03/09/90)

	There is a paper titled 'Excaption Handling in C' by Eric. S.
Roberts, published by Digital Equipment Corp., 1989, which describes a
simple exception handling mechanism implemented with preprocessor. The
resulting code looks something like this:

	exception OpenError;

	TRY
		fp = myopen("test.dat", "r");
	EXCEPT(OpenError)
		printf("Cannot open test.dat\n");
	EXCEPT(....)
		...
	ENDTRY

and in your routines you can use RAISE to raise exceptions.  The exceptions
follow a dynamic call chain at runtime.  Full source code is included in
the paper; works well, according to my (minor) tests.

Kari.
--
Kari Grano	grano@cs.helsinki.fi	Hey, my opinions are just mine..
	"I've got a thousand telephones that don't ring" - R.Z.

libes@cme.nist.gov (Don Libes) (03/10/90)

Check out the paper "An Exception Handler for C" by Eric Allman and
David Been, Summer 1985 USENIX, Portland, OR.  It describes an elegant
system for handling exceptions.  The authors compare it with exception
handling philosophy in other languages including Ada, Mesa, Clu and PL/I.

Has anyone ever used it?  One of these days I'm going to get around to
trying it out.

Don Libes          libes@cme.nist.gov      ...!uunet!cme-durer!libes

duncanb@ibmpcug.co.uk (D G Booth) (03/10/90)

There was a paper about exception handling in C in Software Practice and
Experience back about 1981 (sorry, I dont have the exact reference on me).
That handled exceptions with code like:

exception FILE_ERROR;
...
BEGIN
   f = fopen("afile", "r");
   if (f == NULL) exc_raise(FILE_ERROR);
   ... normal case code.
EXCEPTION
   WHEN(FILE_ERROR)
       ... handle file error
   WHEN(OTHERS)
       ... handle other errors.
       exc_reraise();	/* Pass exception out to next level */
END

I have been using this code (with a few minor changes of my own)
for some time. It is neat and quite clean.

-- 
Automatic Disclaimer:
The views expressed above are those of the author alone and may not
represent the views of the IBM PC User Group.
-- 
---
Duncan Booth, RCP Ltd.                    Didcot, Oxon, UK
duncanb@ibmpcug.co.uk                     Bix: jrichards