graceful failure on segFault?

This is a discussion on graceful failure on segFault? within the C Programming forums, part of the General Programming Boards category; I'm writing a program that's liable to have segfaults in the first few releases (lots of malloc'ed stuff, unlikely to ...

  1. #1
    Registered User Markallen85's Avatar
    Join Date
    Nov 2002
    Posts
    53

    graceful failure on segFault?

    I'm writing a program that's liable to have segfaults in the first few releases (lots of malloc'ed stuff, unlikely to debug it all in time).

    I was just wondering if there's a way I can make the program fail a little more gracefully for the user when it hits one, for example popping up a dialog giving a link to report the bug

    currently the only way I can think of doing this is by wrapping the program in a bat script (or something similar) that will watch for non-zero exit & call a popup program.

    anyone got neater ideas/alternative methods?


    the program's being written in dev-c++ (using C only tho, not c++)
    for win32 systems

    -mark
    "never argue with an idiot, they will drag you down to their level and beat you with experience"

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    Use a signal handler

    Code:
    void trap ( int signal ) {
      // do magic here on a segfault
      // be careful about what memory you use here
    }
    
    int main ( ) {
      signal( SIGSEGV, trap );
      // rest of program
    }
    There might be something a bit more win32 specific
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    See specifically the MSJ article.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. malloc() resulting in a SegFault?!
    By cipher82 in forum C++ Programming
    Replies: 21
    Last Post: 09-18-2008, 12:24 PM
  3. use of printf prevents segfault!
    By MK27 in forum C Programming
    Replies: 31
    Last Post: 08-27-2008, 01:38 PM
  4. Integer Emulation
    By Elysia in forum C++ Programming
    Replies: 31
    Last Post: 03-18-2008, 02:03 PM
  5. Am i a Failure?
    By Failure!!! in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 05-28-2003, 12:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21