Using a lib with enabled exception handling in an application where exception handling is turned off
This question is about a C++ library for Windows and we use Visual C++ as our com开发者_如何学JAVApiler.
We enable exception handling compiler option in our library. We also use throw/catch in a few places.
One of our customers says that they disable exception handling option in their application. Now the question is, whether they would experience any problems if they use our library with their application.
If any exceptions can get emitted out of your library than yes indeed they could have problems. Consider if your library threw an exception that wasn't caught and then propagated back to the application. Since the app isn't built with support for exceptions it won't know how to handle it and most likely will behave incorrectly. If you're lucky it'll crash rather than silently failing in some obscure way.
If you catch all exceptions internally within the library and use only return codes to signal problems to the outside world then things may work out ok (note that this means constructors of public API classes can't throw, and throwing is the only way they can report problems).
精彩评论