Date: Mon, 22 Jan 2001 13:14:54 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: pal cc: djgpp AT delorie DOT com Subject: Re: How to avoid printing the stack trace message ? In-Reply-To: <01c08451$407fab20$37301bd4@pal-s-omnibook> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Mon, 22 Jan 2001, pal wrote: > Is there a way for my program to write a nice user-readable message ("An > internal error occurred. Please bin that program.") instead of the stack > trace when it crashes ? Yes. You need to install a handler for each fatal signal (SIGSEGV, SIGILL, SIGABRT, and SIGFPE at the very least) for that. > Ideally, I would like to get the stack trace into a file (which the user > will be invited to send to me as part of its bug report), and a message > printed instead. In your signal handler installed as described above, redirect handle 2 to a file and then call the function __djgpp_traceback_exit. It will output the traceback to the file. > Also, some finalizers would be happy to run before the > program definitely exits This is probably a mistake, unless you have some hardware interrupts hooked. Normally, a crashing program should do as little as possible, because it might do more damage. For example, imagine some memory corruption in the buffer which you are going to write to your precious file: it is better to leave the file untouched. > I've read through the docs, but they only talk about how to get info from > the stack trace. It sounds as if you looked into the FAQ for this info. That's not the right place to look for information about the library. I suggest to read the documentation of __djgpp_traceback_exit in libc.info. The documentation of the `signal' function is also required reading if you want to install signal handlers. > Surely when you distribute a program you don't want the > user to get stack traces ? Actually, we do. If your program never crashes (as a fully-debugged program should ;-), then it doesn't matter what it does in the case of a crash. If it does crash, you want your users to report the results right away, and the crash message brings lots of useful info. Sweeping the crashes under the carpet is not a good idea, usually.