0

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("");
}
redevil
  • 82
  • 7
  • 1
    You need help with what exactly? – Øyvind Bråthen May 20 '11 at 10:11
  • edited the question, sorry if it was unclear at first – redevil May 20 '11 at 10:12
  • 1
    Of course sometimes Message Boxes are very useful for debugging but what the problem is? – Anton Semenov May 20 '11 at 10:15
  • The edit doesn't really help. In what way is `MessageBox.Show()` failing? – David Heffernan May 20 '11 at 10:15
  • 1
    Wouldn't you rather figure out the "some reason" that's preventing you from using the debugger. Debugging with message boxes can get nasty. – R. Martinho Fernandes May 20 '11 at 10:15
  • @Anton I want to learn how to display debugging information with a message box theres no problem @David its not failing, I just don't know wat to add to it to display debugging information @Martinho doubtful, the problem I have is a version error i suspect, so i don't even wana go there – redevil May 20 '11 at 10:16
  • 1
    What debugging information are you referring to? Is this at a breakpoint in your code? or are you hitting an exception? – IndigoDelta May 20 '11 at 10:17
  • @redevil What's stopping you adding the information you want? We can't guess what your problem is? We don't know what information you want to add. – David Heffernan May 20 '11 at 10:19
  • @Indigo the message box would be where I would put a breakpoint if i was using visual studio's debugger, unfortunately i can't, and there are some features on my application that isn't working and I wana know why, so I guess thats the debugging information I am looking for – redevil May 20 '11 at 10:19
  • @redevil If you can't change the code then you can't add `MessageBox.Show` statements. I recommend that you use the debugger. – David Heffernan May 20 '11 at 10:20
  • @David I need the messagebox to debug my application for me and if there are errors with my application I want it to be displayed, hence I'm here asking how to do tht – redevil May 20 '11 at 10:21
  • @David what do u mean i can't change the codes? – redevil May 20 '11 at 10:22
  • @redevil Sorry, I thought you said you couldn't modify the code. If you can modify the code then just do so. – David Heffernan May 20 '11 at 10:33
  • @David yea but how is the whole idea behind the question here – redevil May 20 '11 at 10:36
  • @redevil Do you know how to write code? – David Heffernan May 20 '11 at 10:37
  • @David not for displayin debugging information with a messagebox which is why im posting this question in the first place – redevil May 20 '11 at 10:39
  • 1
    @redevil what do you mean by debugging information? – David Heffernan May 20 '11 at 10:40
  • @David I have a feature in my application that doesnt work unfortunately I cannot use visual studio's debugger(let's not go there) so if its a logic error with my codes i need to do some debugging with my application hence I'm using the message box to display whatever bug I might have that I don't know of – redevil May 20 '11 at 10:42
  • 1
    @redevil What precisely do you mean by debugging information? You need to be more specific in your question. – David Heffernan May 20 '11 at 10:43
  • @David i meant the information you get after debugging(what's wrong with your application, what error there might be etc.) – redevil May 20 '11 at 10:45
  • @redevil What's wrong with @Vale's answer then, it seems to do exactly what you want. – David Heffernan May 20 '11 at 10:46
  • @David it's very close to what i want, but i cant make it work nth is displayed – redevil May 20 '11 at 10:52

5 Answers5

2

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);
            }
        }
Vale
  • 3,258
  • 2
  • 27
  • 43
1

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

Community
  • 1
  • 1
IndigoDelta
  • 1,481
  • 9
  • 11
0

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...

2GDev
  • 2,478
  • 1
  • 20
  • 32
0

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

Community
  • 1
  • 1
Melodatron
  • 610
  • 4
  • 10
0

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?"

Anton Semenov
  • 6,227
  • 5
  • 41
  • 69