I maintain an open source library that internally uses exceptions during a recursive method call. The exception is taken back on the call stack and in some cases handled, while
I don't believe there is any way to prevent "Halt on All Exceptions" from doing exactly that.
Is there any way to prevent that from happening other than telling users to disable that setting?
Only by avoiding using exceptions for non-error handling purposes (from your description, it almost sounds like your library is breaking this guideline).
This is a semi-clone of this question.
Note that none of the attributes suggested there seemed to accomplish what you are asking when I them with VS2010.
What you can do, is make sure you're always sending the same custom exception type, ie, TigraineNamespace.TigraineException, then instruct your users to go to the Exceptions dialog (Ctrl+Alt+E), click "Add", write "TigraineNamespace.TigraineException", press Enter, then uncheck the checkbox for your particular exception.
This is very much possible. All you need to do is to get Visual Studio seeing the relevant code as non-user code, and then enable the "Just my code" option in the debugger settings:
There are several ways of convincing Visual Studio that your library is not user code. One is to simply compile a release build without PDB files. Another is to mark your code with DebuggerNonUserCodeAttribute.
There’s a demo project showing this stuff in action: https://bitbucket.org/rstarkov/demononusercode/src – note how the methods in MyLibrary are marked with the non-user-code attribute. Even if you tell Visual Studio to stop on "Thrown" for all exceptions, it will still skip the exception in MyLibrary.
For what it’s worth, I do not consider what you’re doing to be wrong. It’s a question of configuring the debugger properly. Not using any exceptions just because someone has set their debugger to stop on everything does not exactly sound right.
No, you cant prevent it.
I recommend the change your design to use return codes/classes instead of exceptions. Exceptions is very expensive for recursive method calls.