0

I already read in some questions that throwing an exception from a dll (or .so) and catching it from the executable is not easy or possible. I have a hobby project where the exe acts a library, that is, is the "functionality provider" for client dlls, more or less, this structure:

ExeProgram::method1() -> Dll::method2() -> ExeProgram::method3() [-> Dll::method4()]

So, my question is: how can a design a good execption design to achieve: - The dll may throw exceptions. - Exception catch should be in ExeProgram.

Is there any way in C++11 to achieve this design?

LeDYoM
  • 949
  • 1
  • 6
  • 21

1 Answers1

0
  1. Make DLL report errors by error codes.
  2. Make a client-side wrapper which handles DLL loading and provides simple interface to it.
  3. Make that wrapper transform error codes to exceptions.
Revolver_Ocelot
  • 8,609
  • 3
  • 30
  • 48
  • I think is the only option but I wanted exactly to avoid error codes. I was thinking in something like re-throwing exceptions, but I suppose is not possible. – LeDYoM Feb 22 '16 at 16:52
  • error codes? How did you manage to time travel from the early 90s to 2016? –  Feb 22 '16 at 18:07
  • @ExcessPhase If you have have any advice on how to avoid locking DLL to be usable only in programs written in specific language and to protect from potential binary compatibility problems when you decide to update dll/program separately, feel free to tell. Generally [letting exception escape module boundary](http://stackoverflow.com/a/7181458/3410396) is a [bad idea](http://stackoverflow.com/a/13991004/3410396). Why do you care if it uses error codes internally? User will only see API which emits exceptions in case of error. – Revolver_Ocelot Feb 22 '16 at 18:17