From 739fb91872993433aa78bca86de6edb3cfa4e327 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 25 Jan 2001 08:05:52 +0000 Subject: [PATCH] Better exception handling behavior git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8765 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++ Documentation/gsdoc/Base.gsdoc | 27 +++++++++++++++++-- Documentation/gsdoc/Base.html | 32 ++++++++++++++++++++--- Source/NSException.m | 47 +++++++++++++++++++++++++++++++++- 4 files changed, 106 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe347caaf..416d1b866 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-01-25 Richard Frith-Macdonald + + * Source/NSException.m: Modify default handler to permit simple + exit as well as abort. + * Documentation/gsdoc/Base.gsdoc: documented environmnet variable + CRASH_ON_ABORT + 2001-01-21 Richard Frith-Macdonald * Source/NSString.m: Fixes for OPENSTEP compatibility in string path diff --git a/Documentation/gsdoc/Base.gsdoc b/Documentation/gsdoc/Base.gsdoc index be1e13222..a529fc309 100644 --- a/Documentation/gsdoc/Base.gsdoc +++ b/Documentation/gsdoc/Base.gsdoc @@ -7,8 +7,8 @@ - 0.1 - 28 February, 2000 + 0.2 + 25 January, 2001 @@ -80,6 +80,29 @@ + + Environment variables +

+ There are some environment variables used by GNUstep base, where + there would be problems onbtaining data from the defaults asystem. +

+ + CRASH_ON_ABORT + + The default exception handler will either cause the program to + simply terminate, or to crash - leaving a core dump. The + standard behavior is to leave a core dump if the library was + built for debugging, and to simply exit if it was not. +

+ The CRASH_ON_ABORT environment variable can be used to + override this behavior. If this is defined to NO, + FALSE, or 0 then the program will simply + exit when an exception occurs. Any other value of the + variable will cause the program to generate a core dump. +

+
+
+
The Foundation classes diff --git a/Documentation/gsdoc/Base.html b/Documentation/gsdoc/Base.html index a630f598c..e62dc8570 100644 --- a/Documentation/gsdoc/Base.html +++ b/Documentation/gsdoc/Base.html @@ -8,8 +8,8 @@
Richard Frith-Macdonald
-

Version: 0.1

-

Date: 28 February, 2000

+

Version: 0.2

+

Date: 25 January, 2001

Base

@@ -78,7 +78,31 @@ for parsing those strings should cope with both cases anyway. -

The Foundation classes

+

Environment variables

+

+ + There are some environment variables used by GNUstep base, where + there would be problems onbtaining data from the defaults asystem. +

+
+
CRASH_ON_ABORT +
+ The default exception handler will either cause the program to + simply terminate, or to crash - leaving a core dump. The + standard behavior is to leave a core dump if the library was + built for debugging, and to simply exit if it was not. +

+ + The CRASH_ON_ABORT environment variable can be used to + override this behavior. If this is defined to NO, + FALSE, or 0 then the program will simply + exit when an exception occurs. Any other value of the + variable will cause the program to generate a core dump. +

+ + +
+

The Foundation classes

-

The GNUstep extension classes

+

The GNUstep extension classes

  • GSMime
  • GSXML diff --git a/Source/NSException.m b/Source/NSException.m index 4accc945c..35d811a1b 100644 --- a/Source/NSException.m +++ b/Source/NSException.m @@ -30,6 +30,8 @@ #include #include +#include // for getenv() + static void _preventRecursion (NSException *exception) { @@ -38,6 +40,9 @@ _preventRecursion (NSException *exception) static void _NSFoundationUncaughtExceptionHandler (NSException *exception) { + const char *c = getenv("CRASH_ON_ABORT"); + BOOL a; + _NSUncaughtExceptionHandler = _preventRecursion; fprintf(stderr, "Uncaught exception %s, reason: %s\n", [[exception name] lossyCString], [[exception reason] lossyCString]); @@ -45,7 +50,47 @@ _NSFoundationUncaughtExceptionHandler (NSException *exception) NSLogError("Uncaught exception %@, reason: %@", [exception name], [exception reason]); */ - abort(); + +#ifdef DEBUG + a = YES; // abort() by default. +#else + a = NO; // exit() by default. +#endif + if (c != 0) + { + /* + * Use the CRASH_ON_ABORT environment variable ... if it's defined + * then we use abort(), unless it's 'no', 'false', or '0, in which + * case we use exit() + */ + if (c[0] == '0' && c[1] == 0) + { + a = NO; + } + else if ((c[0] == 'n' || c[0] == 'N') && (c[1] == 'o' || c[1] == 'O') + && c[2] == 0) + { + a = NO; + } + else if ((c[0] == 'f' || c[0] == 'F') && (c[1] == 'a' || c[1] == 'A') + && (c[2] == 'l' || c[2] == 'L') && (c[3] == 's' || c[3] == 'S') + && (c[4] == 'e' || c[4] == 'E') && c[5] == 0) + { + a = NO; + } + else + { + a = YES; + } + } + if (a == YES) + { + abort(); + } + else + { + exit(1); + } } @implementation NSException