I wanna do something like this:
int main() {
try { runApp(); }
catch(std::except开发者_运维知识库ion const& ex) {
if(runningInDebugger()) throw; // let the IDE show me what went wrong
else displayMsgBox("Something went wrong! " + ex.what());
}
}
Needs to work at least in VS2008 but the more debuggers it supports, the better.
I want it to check for a debugger at runtime. I don't want to do "#ifdef NDEBUG", because I prefer not to do release builds at all (can't be bothered).
So what should I use as a "runningInDebugger()" check?
Under Windows, you can call IsDebuggerPresent to know is there's a debugger attached.
There's also the System.Diagnostics.Debugger.IsAttached if you're working with managed code. Detecting if a debugger is attached in the general case is probably pretty difficult, I would imagine. I normally try and stay away from any changes in behavior while debugging as I think it's bad practice and can make debugging more difficult, but I understand your reasoning for doing so.
精彩评论