If you absolutly need to prevent exceptions from being thrown outside the DLL maybe because it is used by a different compiler or by a program that uses your DLL as a plug-in , then you should typically do something like that:
int SafeExecute(void (*fn)())
{
try
{
fn();
}
catch (const std::bad_alloc &)
{
return ERROR_CODE_FOR_OUT_OF_MEMORY;
}
catch (const std::exception &)
{
return ERROR_CODE_FOR_GENERIC_EXCEPTION;
}
return ERROR_CODE_NONE;
}
If you use a library like MFC that uses other exceptions or handle SEH exceptions, you should add them to the above catch (remember that catch are tried in order until a match is found).
Then for each of your function, you would done something like:
void function1_impl()
{
}
int function1()
{
return SafeExecute(&function1_impl);
}
There are possible variations on this using macros and/or testing exceptions by rethrowing them.
In COM/ActiveX days, it was common to do so because the Component Object Model didn't support exceptions. There was also a way to report error text.