开发者

Using messagebox to display debug information [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I need help on this with some debugging as I am unable to use visual studio's debugger for some reason, any ideas on how to display the debugging information with a message box?

private void ClickforError(object sender, EventArgs e)
{开发者_如何学运维
    MessageBox.Show("");
}


I think you want something like this:

private void ClickforError(object sender, EventArgs e) {
            try {
                // do something
            } catch(Exception ex) {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }


I think I understand. You want a way of automatically displaying all your variables values at a given point in your code. See this question and this question to see why this is not easy.

this looks like a similar question to yours and suggests looking at other inspection tools such as Smart Inspect


I don't know if this can help you, but in a windows application you can add eventhandler to catch all thread exception.

Here is the tutorial where i get the information

This is the the trick :

static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static voidMain()
        {
            Application.ThreadException += new ThreadExceptionEventHandler(new ThreadExceptionHandler().ApplicationThreadException);
            Application.Run(new Form1());
        }
        /// <summary>
        /// Handles any thread exceptions
        /// </summary>
        public class ThreadExceptionHandler
        {
            public void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)
            {
                MessageBox.Show(e.Exception.Message, “An exception occurred:”, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }

But this show only the error messages... if you want some other debug information I think you have to write a Custom Log and write all sort of information befor and after the code you want to debug...


Maybe you should look at this thread? Just putting it out there, but is it possible you're actually the same person? How to use messagebox to output debug information


OK, suppose you have algorythm consist of several steps. When you can "debug it" in this way:

perform step1
display MessageBox with results of step1

perform step2
display MessageBox with results of step2
.
.
.
perform stepN
display MessageBox with results of stepN

When you found out which step ends with error, you should set MessageBoxes in its substeps and also check results of each substep. This iterative approach will lead you to answer for question "Where is the error?"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜