Exception safety
Don
nospam at nospam.com
Fri Dec 12 03:48:13 PST 2008
Sergey Gromov wrote:
> What happens if an extern(Windows) function throws?
Very, very bad things.
> Basically I want my export DLL interface functions to fail gracefully.
> What happens if I don't catch? Currently my typical export looks like
> this, and it looks a bit verbose:
Yup. It's pretty awful, and you need to remember to do it every time.
I do something like:
void doDllRegisterServer()
{
doStuff();
}
extern(Windows) export HRESULT DllRegisterServer()
{
mixin(SafeInvoke("doDllRegisterServer()"));
}
where SafeInvoke creates a string mixin which adds all the catch wrappers.
>
>
> extern(Windows) export HRESULT DllRegisterServer()
> {
> try
> {
> doStuff();
> }
> catch(Exception e)
> {
> myTrace("Shit happens. Reason: " ~ e.msg);
> return E_UNEXPECTED;
> }
> catch(Object obj)
> {
> myTrace("Shit happens. Reason: " ~ obj.toString());
> return E_UNEXPECTED;
> }
> catch
> {
> myTrace("Shit happens. Reason: unknown");
> return E_UNEXPECTED;
> }
> return S_OK;
> }
More information about the Digitalmars-d
mailing list