Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!brl-adm!adm!Alan_T._Cote.OsbuSouth@Xerox.COM From: Alan_T._Cote.OsbuSouth@Xerox.COM Newsgroups: comp.lang.c Subject: Re: How to Trap Runtime System Error under MSC? Message-ID: <11279@brl-adm.ARPA> Date: 15 Jan 88 03:25:21 GMT Sender: news@brl-adm.ARPA Lines: 26 Michael Harris asks, >Can anyone tell me how to trap Microsoft C "serious runtime errors", e.g., >"Error 2000 Stack Overflow", before they print to the terminal screen? The answer to this is somewhat complex. Microsoft C uses a subroutine called "__chkstk" to allocate space for temporaries on the stack. This routine also checks to determine whether the SP register would be decremented below its lowest safe value, and prints the cited error message if it is. Thus, there is no direct way to "trap" this in the parent program. There is, however, light at the end of this tunnel. You could rewrite __chkstk (use MASM, of course) to provide the kind of communication between the child and the parent that you want, and rebuild your child program(s) using the __chkstk object module to override inclusion of the Microsoft version of the routine. Don't forget that the code in the parent routine must initialize the miscellaneous registers and flags that MSC expects in its runtime environment, if it's going to use any C code. Don't, under any circumstances, enter the parent program's trap routine directly in C. I grant that this solution requires a rather clear understanding of the nature of __chkstk and the MSC runtime environment, but that's life. - Al