Results 1 to 8 of 8

Thread: [2005] Write to file on terminate

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    [2005] Write to file on terminate

    If my program crashes, is there a way to write data to a file before it actually terminates?

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: [2005] Write to file on terminate

    i don't think so...

    crash means unexpected end of the program, so i think there isn't no way to handle that...

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

    Re: [2005] Write to file on terminate

    You should handle all the exceptions you can possibly think of that could reasonably be thrown by your code. Assuming that you're building a Windows Forms application, then you handle the UnhandledException event of the application. Note that this will not have any effect while debugging, only in a Release build.

    If it's not a WinForms app then you can just put the entire contents of the Main method inside a Try...Catch block.
    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [2005] Write to file on terminate

    Quote Originally Posted by jmcilhinney
    You should handle all the exceptions you can possibly think of that could reasonably be thrown by your code. Assuming that you're building a Windows Forms application, then you handle the UnhandledException event of the application. Note that this will not have any effect while debugging, only in a Release build.

    If it's not a WinForms app then you can just put the entire contents of the Main method inside a Try...Catch block.

    oops ... i dont think i use a main method

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Write to file on terminate

    Quote Originally Posted by jeffnyc
    oops ... i dont think i use a main method
    And thats perfectly normal, if its a normal WinForms app, as jmcilhinney stated.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [2005] Write to file on terminate

    Quote Originally Posted by Atheist
    And thats perfectly normal, if its a normal WinForms app, as jmcilhinney stated.

    so given that.. what should i do?

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] Write to file on terminate

    Quote Originally Posted by jeffnyc
    so given that.. what should i do?
    This:
    Quote Originally Posted by jmcilhinney
    Assuming that you're building a Windows Forms application, then you handle the UnhandledException event of the application.

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

    Re: [2005] Write to file on terminate

    Go to the Application tab of the project properties, press the View Application Events button, use the drop-down lists at the top of the code window to create a handler for the UnhandledException event and then place whatever code you want executed when your app encounters an unexpected fatal error in that method.
    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

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