Results 1 to 10 of 10

Thread: [RESOLVED] [2005] Trouble with global exception handler

  1. #1

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Resolved [RESOLVED] [2005] Trouble with global exception handler

    I am having trouble getting the global exception handler from this thread to work for me. I've tried a variety of copy and paste locations, but believe that I'm missing something rather simple and obvious.

    For clarity, I put the code in the place of the Class Form1 code. It wouldn't compile without a button, so I added one, then on compilation the button wasn't there. I threw the code into Form1.Designer.vb, the button was there, and the exception was thrown correctly, but the exception was unhandled.

    Thanks in advance
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Trouble with global exception handler

    Don't even bother. VB 2005 has in-built functionality for that. Go to the Application tab of the project properties and press the View Application Events button, then create a handler for the UnhandledException event. You can choose to keep the application running, exit or you can even use Application.Restart to close and restart the app.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: [2005] Trouble with global exception handler

    That sounds like a good idea. I tried that, and I ran into some problems. I didn't get exactly what you meant with some of the directions (specifically the navigation - the names of the things to click/press), but I made some guesses and got something resembling what you described.

    The problem is displayed in the attachment. I tried compiling the program without the exception handler and it worked fine, then I added the UnHandledException error and got the error shown... The form doesn't load or anything, and the dissambler shows some assembly and highlights a line (I'll post this if it'll help).

    Any thoughts?

    EDIT: had some trouble with the image size, so had to fiddle with it for a little while. the bits cut off are not important (they are the standard variables etc for the routine and part of a commented out line)
    Attached Images Attached Images  
    Last edited by ZaNi; Jul 3rd, 2006 at 12:31 AM.
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  4. #4

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: [2005] Trouble with global exception handler

    Bumpity...

    Has anyone gotten a global exception handler to work? If anyone could post a version that works, that should be enough for me to figure this out...

    Thanks in advance
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Trouble with global exception handler

    Like I said, the functionality is already there in VB 2005 and I've got exactly that to work in every VB 2005 application I've written. I don't know why you're getting that error but it is not an indication that the process doesn't work. It's an indication that there is an issue with your project specifically. Start a new project and add only that event handler, then add some code somewhere that you know will throw an exception and watch it work. Note that it will only kick in in a Release build though, because the debugger will catch unhandled exceptions first in a Debug build.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: [2005] Trouble with global exception handler

    Ok. All that information is accurate as far as I can tell. I'm not sure what happened in the other program, but it worked in a new program (and the debugger overrode it).

    How do you get the Release build (a newbie question... I know)? Is it through publishing or is there another way?
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  7. #7
    Junior Member
    Join Date
    Feb 2006
    Posts
    17

    Re: [2005] Trouble with global exception handler

    Build > Build [project name]. Then it wil be in \bin\release in your project's folder.

  8. #8

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: [2005] Trouble with global exception handler

    Ok. Tried the build, worked fine, got error, blah blah blah.

    End result. I have WindowsApplication1 built with the global exception handler supposed to use msgbox("Exception: " & e.tostring). Attached is what I got when I ran the built program from windows explorer (note: this is not what I expected from the exception handling).

    EDIT: The code was Dim tmp As Integer = 0, tmp /= 0... I'm surprised the compiler didn't prevent this though...
    Attached Images Attached Images  
    Last edited by ZaNi; Jul 3rd, 2006 at 09:56 PM.
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  9. #9

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: [2005] Trouble with global exception handler

    I've done some more testing on this, and it seems that the code will work fine as long as the project is not built and run in windows. If the program is run in the windows environment, the source code for the program seems to get damaged in some way so that any further building/running of the program (regardless of whether it is in the dev environment or windows environment) generates the assembly error I described earlier:

    "No symbols are loaded for any call stack frame. The source code cannot be displayed."

    The options given are OK and Show Dissembly. From this point onwards, the only way to get the program to run again is to remove (either by comment or deletion) the unhandled exception routine from the ApplicationEvents. Creation of a new unhandled exception event (from the template) generates the same error.

    All this is a little annoying, because I would like to have a global exception handler as opposed to having the exact same try/catch in almost every function.

    I don't know if it makes any difference, but this is run over a network drive, and suffers from limited privilages (I could try escalating this to full privilages, but it seems unlikely to help).

    I cannot think of anymore information to add to this at this point. If anybody has any suggestions I would really appreciate it. If anymore information is needed, just ask and I'll post it ASAP.

    Thanks in advance
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  10. #10

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: [2005] Trouble with global exception handler

    OK FINALLY!!!

    I've cracked the problem. I created the entire project locally then ran it and it worked!!! To follow up, I copied only the files in the release directory into a directory on the network drive. Upon running (the same .exe mind you), the error was the windows error above.

    I don't know what it is about networks that messes with visual basic at such a fundamental level (note that I have entire project unable to compile if they had the global error handler included after one running of the built .exe over the network), but I will create test project locally from now on.

    I'm posting this to let anybody who reads this know about the problems I had (so if they have the same problems, they have another possible solution), and to explain why the thread is now resolved.

    yay!

    EDIT: I'd like to acknowledge the support from jmcilhinney. I wouldn't have solved this without his help.
    Last edited by ZaNi; Jul 4th, 2006 at 07:15 PM.
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width