Reputation: 5422
I have a c++ program and I want to display the line number of where the program crashes in the console ! I'm using VS2010! is that even possible? I use opencv , and opencv does it ! any idea?
Upvotes: 3
Views: 3101
Reputation: 16256
Sometimes you cannot use a debugger, e.g. when you cannot reproduce the crash locally. In this case you need to put try/catch
on top-level to catch and report all exceptions (on Windows make sure you also catch structured exceptions) and to subscribe to signals to catch and report SEGFAULT
s etc.
Then you can log stack trace (not portable and requires debug symbols) or create a mini-dump (not portable).
Upvotes: 1
Reputation: 2702
I'd suggest using a debugger with reasonable haltpoints and check if those haltpoints are reached. I prefer this one over console debug messages as it doesn't pollute your code.
Upvotes: 2
Reputation: 56479
I had a same issue, there was a code and I wasn't able to debug it (it had to run without stopping). I put below code before every suspecting line:
cout << __LINE__ << endl;
After that, when it crashed, I could trap the problem.
But a standard way is using a debugger and put conditional breakpoints. (I'm not sure it helps you)
Upvotes: 5