From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10f8a1,e7e13c943c611b62 X-Google-Attributes: gid10f8a1,public X-Google-Thread: 102b75,be3d6a6131c61fa7 X-Google-Attributes: gid102b75,public X-Google-Thread: 1164f8,be3d6a6131c61fa7 X-Google-Attributes: gid1164f8,public From: dpbsmith@world.std.com (Daniel P. B. Smith) Subject: Re: Exception handling Date: 1999/04/24 Message-ID: #1/1 X-Deja-AN: 470483723 References: <36E9F2A0.9A401A09@pacific.net.sg> <924046418.053.46@news.remarQ.com> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.arch,comp.sys.dec,vmsnet.alpha In article , Zalman Stern wrote: >Daniel P. B. Smith (dpbsmith@world.std.com) wrote: >: In my case: I write "front-end" code; the code calls a library, which is >: provided by the company we are OEM-ing from; the library in turn makes >: callbacks to "back-end" routines that I provide. The library is >: documented as if were written in C, and their code examples are in C. >: But, silly me, I thought that backward compatibility with C was almost >: C++'s whole reason for being, and that I was reasonably safe mixing and >: matching as long as I used extern "C" directives properly in my headers. >: I _did_ wonder why the program crashed whenever one of my callback >: routines threw an exception... > >You must wrap all callback routines with code that catches all exceptions >and turns them into error returns. This should be obvious in the case of a >callback routine that returns an error code. The compiler could not >possibly automagically turn a thrown exception into the right kind of error >code return. I didn't expect it to; I expected the exception to get thrown upward past and through the C library layer and get caught by the exception handlers in my calling routines above. That is, to do what it would have done if the C source code in the library had been compiled as C++ code by the C++ compiler. >The binary compatibility gotcha is a big lose. It means that even if folks >could be convinced to use a richer calling convention for standard system >services and libraries (which I doubt will happen), different compilers on >the same platform would have to be modified to conform to the same binary >calling convention. Yeah, well, OK, I was stupid... but it's been YEARS since I had to worry seriously about different compilers generating different calling conventions... I don't see why C++ books don't BEGIN their exception-handler chapters by warning you about this, instead of with encomia encouraging you to use the feature. Do writers of C++ books just assume that you have access to all the source code needed to build your program? -- Daniel P. B. Smith dpbsmith@world.std.com