0

Is there a way of temporally disable first-chance exceptions in Visual C++?

Something like this:

void someFunc() {
   disableFirstChanceExceptions();

   try {
     // some code
   }
   catch (std::exception& e) {
     // some code
   }
   catch (...) {
     // some code
   }

   enableFirstChanceExceptions();
}

I know what first-chance-exceptions are and how to use them.

The problem is, that I am distributing a DLL, in which exceptions are used.
Unfortunately if a customer is using a debugger with his program, he will notice my intern exceptions.
It is not that I want to hide them, it is more that I want to get rid of these support questions.

ConfusedSushi
  • 874
  • 8
  • 16

2 Answers2

3
  • Your code throws exceptions.
  • Your customers insist on running debuggers against your code, and explicitly configure it to break on first-chance exceptions.

You have basically two options:

  • don't throw exceptions, or
  • ignore when your customer is being stupid. What your code does internally is none of their business as long as it works as intended.

I'd suggest the latter. If they have a problem with exceptions being thrown and caught inside third-party code, they'll find themselves unable to use a lot of libraries. They'll need to grow up and start acting like they know what they're doing.

jalf
  • 243,077
  • 51
  • 345
  • 550
0

First chance exceptions are not something that can be turned on and off in your code (speaking only about windows, vs, c++ chain, not familiar with other platforms). This is construct is built into the run time system to make debugging possible. The debugger can be configured to ignore some or all first chance exceptions. You can use ctrl + alt + e to bring up the VS debugger's exception handling behavior menu. This will allow clients debugging to filter what the want caught by the debugger.

Unknown1987
  • 1,671
  • 13
  • 30
  • I know about this. I also know about that I configure my debugger to ignore them, but I can't configure the debuggers of my customers. I was hoping there exists something like http://msdn.microsoft.com/en-us/library/xcb2z8hs%28v=vs.100%29.aspx which also just a debugger feature. – ConfusedSushi Mar 22 '12 at 13:02
  • 3
    IF your customers are using a debugger without *knowing* how to use a debugger, I don't think there's any way in which you can win. – jalf Mar 22 '12 at 13:13
  • It sounds like your customers are seeing your internal use of exceptions even if the exception is correctly being handled by your lib. As I've said first chance exceptions are not something you can turn off - it is a feature of the debugger. Direct your customers to learn how to disable specific first chance exceptions. – Unknown1987 Mar 16 '14 at 10:09