mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Better exception handling behavior
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8765 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
603e9ad895
commit
e6a40fa627
4 changed files with 106 additions and 7 deletions
|
@ -1,3 +1,10 @@
|
|||
2001-01-25 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* 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 <rfm@gnu.org>
|
||||
|
||||
* Source/NSString.m: Fixes for OPENSTEP compatibility in string path
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
<email address="rfm@gnu.org"/>
|
||||
<url url="http://www.gnustep.org/developers/whoiswho.html"/>
|
||||
</author>
|
||||
<version>0.1</version>
|
||||
<date>28 February, 2000</date>
|
||||
<version>0.2</version>
|
||||
<date>25 January, 2001</date>
|
||||
</head>
|
||||
<body>
|
||||
<chapter>
|
||||
|
@ -80,6 +80,29 @@
|
|||
</desc>
|
||||
</deflist>
|
||||
</subsect>
|
||||
<subsect>
|
||||
<heading>Environment variables</heading>
|
||||
<p>
|
||||
There are some environment variables used by GNUstep base, where
|
||||
there would be problems onbtaining data from the defaults asystem.
|
||||
</p>
|
||||
<deflist>
|
||||
<term>CRASH_ON_ABORT</term>
|
||||
<desc>
|
||||
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.
|
||||
<p>
|
||||
The CRASH_ON_ABORT environment variable can be used to
|
||||
override this behavior. If this is defined to <em>NO</em>,
|
||||
<em>FALSE</em>, or <em>0</em> 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.
|
||||
</p>
|
||||
</desc>
|
||||
</deflist>
|
||||
</subsect>
|
||||
</section>
|
||||
<section>
|
||||
<heading>The Foundation classes</heading>
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
<dt><a href ="http://www.gnustep.org/developers/whoiswho.html">Richard Frith-Macdonald</a>
|
||||
<dd>
|
||||
</dl>
|
||||
<p>Version: 0.1</p>
|
||||
<p>Date: 28 February, 2000</p>
|
||||
<p>Version: 0.2</p>
|
||||
<p>Date: 25 January, 2001</p>
|
||||
<h2><a name ="cont-0">Base</a></h2>
|
||||
<p>
|
||||
|
||||
|
@ -78,7 +78,31 @@
|
|||
for parsing those strings should cope with both cases anyway.
|
||||
|
||||
</dl>
|
||||
<h3><a name ="cont-4">The Foundation classes</a></h3>
|
||||
<h4><a name ="cont-4">Environment variables</a></h4>
|
||||
<p>
|
||||
|
||||
There are some environment variables used by GNUstep base, where
|
||||
there would be problems onbtaining data from the defaults asystem.
|
||||
</p>
|
||||
<dl>
|
||||
<dt>CRASH_ON_ABORT
|
||||
<dd>
|
||||
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.
|
||||
<p>
|
||||
|
||||
The CRASH_ON_ABORT environment variable can be used to
|
||||
override this behavior. If this is defined to <em>NO</em>,
|
||||
<em>FALSE</em>, or <em>0</em> 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.
|
||||
</p>
|
||||
|
||||
|
||||
</dl>
|
||||
<h3><a name ="cont-5">The Foundation classes</a></h3>
|
||||
<ul>
|
||||
<li><a href ="NSArchiver.html">NSArchiver</a>
|
||||
<li><a href ="NSArray.html">NSArray</a>
|
||||
|
@ -150,7 +174,7 @@
|
|||
<li><a href ="NSUserDefaults.html">NSUserDefaults</a>
|
||||
<li><a href ="NSValue.html">NSValue</a>
|
||||
</ul>
|
||||
<h3><a name ="cont-5">The GNUstep extension classes</a></h3>
|
||||
<h3><a name ="cont-6">The GNUstep extension classes</a></h3>
|
||||
<ul>
|
||||
<li><a href ="GSMime.html">GSMime</a>
|
||||
<li><a href ="GSXML.html">GSXML</a>
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <Foundation/NSThread.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
|
||||
#include <stdlib.h> // 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
|
||||
|
|
Loading…
Reference in a new issue