Top-Master
Top-Master

Reputation: 8816

Is replacing all standard error-dialogs with debug-breaks or error-throws possible?

I would like to replace any standard error-dialog with throw or debug-break (with standard I mean anything which is not explicitly written by me) since like in the reason-section described, it would cause debugging of a Windows-Service sometimes to be impossible.

to accomplish this I did try defining something like:

-D "_HAS_ITERATOR_DEBUGGING=0"

but above did just disable the error-dialogs and is really not enough to track down the issues, so I would like it to throw-exception or to debug-break instead of showing the error-dialog.

is there anything else you would suggest me to define or do?

Reason:

While developing a Windows-Service, I had some hard times to find a bug which was causing the server to crash:

Reproduce:

by running below in a service (compiled in debug-mode) you can reproduce this issue:

#include <unordered_map>

// will cause crash by trying to increment iterator pointing to end
inline static void simulateCrash() {
    typedef std::unordered_map<quint32, quint32> Hash;
    Hash list;
    list[0xC001] = 0xDEAD;
    Hash::iterator it = list.begin();
    it = list.erase(it);
    ++it; // should crash here
}

Upvotes: 1

Views: 99

Answers (1)

Jarod42
Jarod42

Reputation: 218138

You probably want to use _set_invalid_parameter_handler to overwrite default handler which terminates the program and displays a runtime error message.

_CrtSetReportMode is also useful to avoid dialog from _CrtDbgReport (used in several checks).

Upvotes: 2

Related Questions