SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

trying to print out debugging information

Last post 07-16-2017 9:48 PM by sbrand. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-09-2017 7:10 PM

    trying to print out debugging information

    My vb.net application was working both from SharpDevelop and clicking on the .exe file. Then it stopped working from the .exe and I'm trying to debug--and at the same time learn how to extend my debugging knowledge to figure out other problems.

    I have tried:

    try:
        form = MainForm.MainForm()
        Application.Run(form)
    except e:
        print e
        MessageBox.Show(e)
        pass

    I've put the above int he .program file but then the GU never shows. Just a flash and back to SharpDevelop. When I delete the MessageBox.Show(e) then it runs again but I cannot figure out how to obtain/read errors. Either they are occurring so quickly that when the "black window" (is that the console?) closes I lose them or they are not printing. Nothing prints in the Error pane (or Warning pane) but that would be great if I could direct errors there.

    Any suggestions? Thanks in advance.

    Steve

     

  • 07-12-2017 6:41 PM In reply to

    Re: trying to print out debugging information

    Ok...I've helped myself "slightly". When I compile instead to a Console app then error information shows up in the console window so I can refer to that and see where I got tripped up. That has been helpful. Also using MessageBox.Show(str(e)) rather than MessageBox.Show(e) has helped.

    BUT--Now when I go back to compile as a Windows app there are no errors but the GUI does NOT display. If I go to the debug directory and click on the generated .exe file the GUI comes up and it works as expected.

    I had this type of error before when I first started working with SharpDevelop---I would be writing code and suddenly trying to Run and Debug I would lose the display of the GUI. When I commented out lines of code that I had just placed the GUI returned. So are I haven't gotten to figuring out why those lines gave me trouble but is there anyway to return to a Windows app so I don't have to keep clicking on the executable after compiling?

    Thanks.

    Steve

     

     

  • 07-16-2017 7:10 PM In reply to

    Re: trying to print out debugging information

    sbrand:

    I have tried:

    try:
        form = MainForm.MainForm()
        Application.Run(form)
    except e:
        print e
        MessageBox.Show(e)
        pass

    My first suggestion would be to not do that. If something within Application.Run has thrown an unhandled exception then by the time you catch it, Application.Run isn't running any more, so you probably no longer have an application to display a MessageBox. Instead, try handling any exceptions within your MainForm class. First, have a good look at its constructor for anything which might be throwing an exception, and if you find anything then you really ought to move it out of the constructor (really the constructor should be doing the bare minimum to initialise the class, and certainly shouldn't be doing lots of complex stuff).

    And then consider putting the exception handling into your event handlers, e.g. (sorry, this is in C# but hopefully you'll get the gist)

    private void MyButton_Click(object sender, EventArgs e)

    {

        try

        {

            // do stuff

        }

        catch (Exception ex)

        {

            MessageBox.Show(ex.ToString());

        }

    }

    If you do this for every event handler, and you've ensured that your MainForm's constructor can't throw any exceptions, then any other exceptions will be caught and reported by your event handlers and the application will continue to run and respond to events until you close or kill it. Or you could be more selective and only add exception handling in event handlers that you think might throw exceptions, up to you...

    Simon

  • 07-16-2017 9:48 PM In reply to

    Re: trying to print out debugging information

    Thanks for the reply Simon.

    That makes sense.

    Still learning....

Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.