How to locate the source code which pops the error message – More easily.

17 04 2008

While debugging huge code bases, unexpectedly some error messages can be popped up. Most probably we might be seeing it for the first time and don’t have any idea, from which location of the code base, the error message get fired. How to locate it easily?

Just follow the steps –

1) Start the project by F5.
2) Do the steps to make the error messagebox to be shown. Now the error message will be shown.
3) Now instead of clicking of in the error message, take debugger and click menu, Debug -> Break.
4) Now take Debug -> Threads to see the threads running in your application.
5) You can see one of your thread, which is paused in a messagebox showing routine.
6) Select that thread and click SetFocus, to focus that thread.
7) Now take the Call Stack by Alt+7 and iterate through it from top to bottom.
8 ) You see one familiar function? Yes! its the one which pops the error message. Now go and fix the bug 😉

You can also put a breakpoint by finding the memory address of the functions that can be used for showing error messages. But, if the application uses some custom dialogs, then you’ve to put more effort. This method is the handy one with least headaches. Try it!

Targeted Audience – Beginners.