Re: How do I write exception safty code?
On Sep 13, 1:29 am, "dragon9" <maigre_dra...@126.com> wrote:
Thanks very much, my question is how to wrap C-api functions with excepti=
on
safety.
example:
FindFirstFile(),etc.
If it's a function from a C API, you don't need to do anything
with regards to exception safety, since the function will never
throw. Otherwise, it couldn't be used from C. In particular,
both the Windows API and Posix are C, and none of the functions
in these API's ever raise an exception. (I think. I'm 100%
sure about Posix, but I think Windows is the same.)
If you want the function to throw for certain types of errors,
you'll have to wrap it, check the return status, and manually
throw the exception you want for the types of errors you want.
Regardless of whether you want to throw or not, I would strongly
recommend wrapping all of the system API in some sort of
platform neutral C++ interface; I use something roughly similar
to java.io.File, for example, with different implementations for
Windows and for Posix/Linux. And some of the functions in this
class do throw, for certain types of errors.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34