Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!amdahl!pyramid!voder!tolerant!vsi1!steve From: steve@vsi1.UUCP (Steve Maurer) Newsgroups: comp.lang.c++ Subject: Re: Proposal for Exceptions for C++ Message-ID: <459@vsi1.UUCP> Date: 31 Mar 88 19:29:38 GMT References: <8180006@eecs.nwu.edu> <2229@phoenix.Princeton.EDU> <837@cresswell.quintus.UUCP> <2243@phoenix.Princeton.EDU> Reply-To: steve@vsi1.UUCP (Steve Maurer) Organization: Vicom Systems Inc. San Jose, Cal. Lines: 81 Article 303 of comp.lang.c++: Path: vsi1!steve From: steve@vsi1.UUCP (Steve Maurer) Newsgroups: comp.lang.c++ Subject: Re: Proposal for Exceptions for C++ Message-ID: <457@vsi1.UUCP> Date: 31 Mar 88 19:26:58 GMT References: <8180006@eecs.nwu.edu> <2229@phoenix.Princeton.EDU> <837@cresswell.quintus.UUCP> <2243@phoenix.Princeton.EDU> Reply-To: steve@vsi1.UUCP (Steve Maurer) Organization: Vicom Systems Inc. San Jose, Cal. Lines: 71 I have a question. What's wrong with doing this? Have an exception keyword: "exception", placed before the exception processing function. Have a identifier following which is the "name" of the exception (much like structure identifiers). Have a couple of predefined identifiers for the most common exceptions: divide by zero, stack overflow, etc. use "raise" with these identifiers. redefine "resume" to not disturb the flow of control Example Of Use: extern int counter; extern int result; exception userfoobar /* a user defined exception */ { counter--; } exception zerodivide /* zerodivide is a predefined exception */ { /* ...raised on divide by zero errors */ counter++; result = 0; if (counter > 200) exit(); resume; /* actually a redundant statement, resume is implicit */ } exception noresume /* noresume is a predefined exception */ { /* ...raised when resuming generates an */ printf("error could not resume\n"); /* immediate error */ exit(-1); } // exit is also redundant in this case, a few predefined // exceptions are automatically fatal (they exit no matter what) //--------------- int counter, result; main(int ac; char **av) /* example use */ { float foo[1000], bar[1000]; int i; getinputarray(foo); /* inputs data from somewhere */ getinputarray(bar); for (i = 0; i < 1000; i++) { result = foo[i] / bar[i]; /* raises exception on / by 0 */ /* any other processing */ /* increments counter */ } raise zerodivide; /* raise a divide by zero exception */ raise userfoobar; /* raise a userfoobar exception */ } This is simple to use, powerful (though not quite complete), and would not be too much of a pain to translate into any reasonable C implementation (using signals/longjmps). Steve Maurer tolerant!vsi1!steve octopus!vsi1!steve