Results 1 to 13 of 13

Thread: Unhandled exception when closing the program

  1. #1

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Unhandled exception when closing the program

    Hi guys. Our application got this exception after it was closed... I was wondering how we can solve this...
    Attached Images Attached Images  
    Attached Files Attached Files
    ====================
    ほんとにどもありがとう!

    Rie Ishida

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

    Re: Unhandled exception when closing the program

    The error message indicates that you are modifying a collection inside a For Each loop that enumerates it, which is not allowed. If you're getting this error when you run your app then it indicates that you haven't tested it properly because that sort of thing you be found while testing/debugging.
    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
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Re: Unhandled exception when closing the program

    Does this have something to do with how we close forms? We closed some of the forms in our application using the .Dispose method.
    ====================
    ほんとにどもありがとう!

    Rie Ishida

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

    Re: Unhandled exception when closing the program

    Quote Originally Posted by riechan View Post
    Does this have something to do with how we close forms? We closed some of the forms in our application using the .Dispose method.
    That shouldn't really matter, although you shouldn't really be calling Dispose on a form to close it. You should either be calling Close or else setting the DialogResult if it was displayed with ShowDialog. The only time you should be calling Dispose explicitly is when you're done with a modal dialogue but, even then, you should be disposing implicitly with a Using block, so an explicit Dispose call shouldn't ever be necessary.

    Like I said though, it shouldn't matter in this context. The problem is exactly as I said: you're almost certainly modifying a collection within a For Each loop.
    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

  5. #5

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Re: Unhandled exception when closing the program

    Quote Originally Posted by jmcilhinney View Post
    The problem is exactly as I said: you're almost certainly modifying a collection within a For Each loop.
    Modifying a collection within a For Each loop? But, as far as I know, I didn't even use a for each loop in my application. How is this possible?
    ====================
    ほんとにどもありがとう!

    Rie Ishida

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

    Re: Unhandled exception when closing the program

    Quote Originally Posted by riechan View Post
    Modifying a collection within a For Each loop? But, as far as I know, I didn't even use a for each loop in my application. How is this possible?
    Hmmm... let me use my vast knowledge of your application to answer that. Seriously though, that's why you catch exceptions and debug code. Maybe there's something dodgy going on behind the scenes and its not your loop or collection. If you either examine the exception in the debugger or catch the exception and examine it at run time to see exactly where it occurs. Try handling the UnhandledException event of the application and examining the exception, particularly the stack trace.
    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

  7. #7

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Re: Unhandled exception when closing the program

    That's rather weird. I know I have placed Try-Catch statements on all the events that I've used, except for the form_closing ones. Should I try using a general exception handler or is there a specific exception handler used for this kind of situation?
    ====================
    ほんとにどもありがとう!

    Rie Ishida

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

    Re: Unhandled exception when closing the program

    Quote Originally Posted by riechan View Post
    Should I try using a general exception handler
    That seems to be what I suggested.
    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

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Unhandled exception when closing the program

    Hey,

    Or, perhaps, if you show us the code that is causing the error, we might be able to help.

    Gary

  10. #10

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Re: Unhandled exception when closing the program

    Is it because I used Application.Exit in the form_closing event? Seriously, I'm not getting any error messages even if I'm using try-catch. Weird.
    ====================
    ほんとにどもありがとう!

    Rie Ishida

  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Unhandled exception when closing the program

    Hey,

    Without knowing more about your application, i.e. the code that you are using, it is going to be difficult to help you much more.

    Have you tried stepping through your code in the debugger, using breakpoints. At some point, an exception is getting thrown in your code that you are not handling. What course of actions do you take in your application to make it happen? Do you click a button? If so, set a breakpoint in the code, at this point, and then start stepping through the code.

    Gary

  12. #12

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Re: Unhandled exception when closing the program

    This only happens when we run the application after it has been deployed (installed). It's running just fine when we run it using VS, that's why I don't know which code to place here.
    ====================
    ほんとにどもありがとう!

    Rie Ishida

  13. #13
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Unhandled exception when closing the program

    Ok, so perhaps some information about what your application does?

    Have you deployed all necessary 3rd party dll's that your application needs? Are there any specific Application Settings that need to be changed, i.e. where a file is located, the installation path. Have you got any hard coded references to files in your application, that aren't there on the deployed system?

    There has to be something different between the two installations.

    A good idea would be to add logging to your application, that way you can see exactly what your code is doing when it throws the exception.

    Gary

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