mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Applied and tidied patch for more informative exceptions.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17962 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3baba2414f
commit
034969baa0
2 changed files with 50 additions and 26 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Fri Oct 24 07:55:00 2003 Stefan Urbanek <stefanu@altair.des.elf.stuba.sk>
|
||||||
|
|
||||||
|
* Source/GSArray.m: make exception messages more informative.
|
||||||
|
|
||||||
Thu Oct 23 17:45:00 2003 Richard Frith-Macdonald <rfm@gnu.org>
|
Thu Oct 23 17:45:00 2003 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSSocketPort.m:
|
* Source/NSSocketPort.m:
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "Foundation/NSException.h"
|
#include "Foundation/NSException.h"
|
||||||
#include "Foundation/NSPortCoder.h"
|
#include "Foundation/NSPortCoder.h"
|
||||||
#include "Foundation/NSDebug.h"
|
#include "Foundation/NSDebug.h"
|
||||||
|
#include "Foundation/NSValue.h"
|
||||||
|
|
||||||
static SEL eqSel;
|
static SEL eqSel;
|
||||||
static SEL oaiSel;
|
static SEL oaiSel;
|
||||||
|
@ -131,7 +132,7 @@ static Class GSInlineArrayClass;
|
||||||
_count = i;
|
_count = i;
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"Tried to add nil to array"];
|
format: @"Tried to init array with nil to object"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_count = count;
|
_count = count;
|
||||||
|
@ -268,8 +269,7 @@ static Class GSInlineArrayClass;
|
||||||
{
|
{
|
||||||
if (index >= _count)
|
if (index >= _count)
|
||||||
{
|
{
|
||||||
[NSException raise: NSRangeException
|
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
||||||
format: @"Index out of bounds"];
|
|
||||||
}
|
}
|
||||||
return _contents_array[index];
|
return _contents_array[index];
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ static Class GSInlineArrayClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject:argument
|
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: argument
|
||||||
{
|
{
|
||||||
unsigned i = _count;
|
unsigned i = _count;
|
||||||
|
|
||||||
|
@ -316,6 +316,26 @@ static Class GSInlineArrayClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) _raiseRangeExceptionWithIndex: (int)index from: (SEL)sel
|
||||||
|
{
|
||||||
|
NSDictionary *info;
|
||||||
|
NSException *exception;
|
||||||
|
NSString *reason;
|
||||||
|
|
||||||
|
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
[NSNumber numberWithInt: index], @"Index",
|
||||||
|
[NSNumber numberWithInt: _count], @"Count",
|
||||||
|
self, @"Array", nil, nil];
|
||||||
|
|
||||||
|
reason = [NSString stringWithFormat: @"Index %d is out of range %d (in '%@')",
|
||||||
|
index, _count, NSStringFromSelector(sel)];
|
||||||
|
|
||||||
|
exception = [NSException exceptionWithName: NSRangeException
|
||||||
|
reason: reason
|
||||||
|
userInfo: info];
|
||||||
|
[exception raise];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GSInlineArray
|
@implementation GSInlineArray
|
||||||
|
@ -348,7 +368,7 @@ static Class GSInlineArrayClass;
|
||||||
_count = i;
|
_count = i;
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"Tried to add nil to array"];
|
format: @"Tried to init array with nil object"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_count = count;
|
_count = count;
|
||||||
|
@ -384,7 +404,7 @@ static Class GSInlineArrayClass;
|
||||||
if (ptr == 0)
|
if (ptr == 0)
|
||||||
{
|
{
|
||||||
[NSException raise: NSMallocException
|
[NSException raise: NSMallocException
|
||||||
format: @"Unable to grow"];
|
format: @"Unable to grow array"];
|
||||||
}
|
}
|
||||||
_contents_array = ptr;
|
_contents_array = ptr;
|
||||||
_capacity += _grow_factor;
|
_capacity += _grow_factor;
|
||||||
|
@ -410,15 +430,11 @@ static Class GSInlineArrayClass;
|
||||||
{
|
{
|
||||||
if (i1 >= _count)
|
if (i1 >= _count)
|
||||||
{
|
{
|
||||||
[NSException raise: NSRangeException format:
|
[self _raiseRangeExceptionWithIndex: i1 from: _cmd];
|
||||||
@"in %@:, index %d is out of range",
|
|
||||||
NSStringFromSelector(_cmd), i1];
|
|
||||||
}
|
}
|
||||||
if (i2 >= _count)
|
if (i2 >= _count)
|
||||||
{
|
{
|
||||||
[NSException raise: NSRangeException format:
|
[self _raiseRangeExceptionWithIndex: i2 from: _cmd];
|
||||||
@"in %@:, index %d is out of range",
|
|
||||||
NSStringFromSelector(_cmd), i2];
|
|
||||||
}
|
}
|
||||||
if (i1 != i2)
|
if (i1 != i2)
|
||||||
{
|
{
|
||||||
|
@ -450,7 +466,7 @@ static Class GSInlineArrayClass;
|
||||||
if ((self = [self initWithCapacity: count]) == nil)
|
if ((self = [self initWithCapacity: count]) == nil)
|
||||||
{
|
{
|
||||||
[NSException raise: NSMallocException
|
[NSException raise: NSMallocException
|
||||||
format: @"Unable to make array"];
|
format: @"Unable to make array while initializing from coder"];
|
||||||
}
|
}
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
|
@ -476,7 +492,7 @@ static Class GSInlineArrayClass;
|
||||||
_count = i;
|
_count = i;
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"Tried to add nil to array"];
|
format: @"Tried to init array with nil object"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_count = count;
|
_count = count;
|
||||||
|
@ -490,13 +506,21 @@ static Class GSInlineArrayClass;
|
||||||
|
|
||||||
if (!anObject)
|
if (!anObject)
|
||||||
{
|
{
|
||||||
[NSException raise: NSInvalidArgumentException
|
NSException *exception;
|
||||||
format: @"Tried to insert nil to array"];
|
NSDictionary *info;
|
||||||
|
|
||||||
|
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
[NSNumber numberWithInt: index], @"Index",
|
||||||
|
self, @"Array", nil, nil];
|
||||||
|
|
||||||
|
exception = [NSException exceptionWithName: NSInvalidArgumentException
|
||||||
|
reason: @"Tried to insert nil to array"
|
||||||
|
userInfo: info];
|
||||||
|
[exception raise];
|
||||||
}
|
}
|
||||||
if (index > _count)
|
if (index > _count)
|
||||||
{
|
{
|
||||||
[NSException raise: NSRangeException format:
|
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
||||||
@"in insertObject:atIndex:, index %d is out of range", index];
|
|
||||||
}
|
}
|
||||||
if (_count == _capacity)
|
if (_count == _capacity)
|
||||||
{
|
{
|
||||||
|
@ -608,9 +632,7 @@ static Class GSInlineArrayClass;
|
||||||
|
|
||||||
if (index >= _count)
|
if (index >= _count)
|
||||||
{
|
{
|
||||||
[NSException raise: NSRangeException
|
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
||||||
format: @"in removeObjectAtIndex:, index %d is out of range",
|
|
||||||
index];
|
|
||||||
}
|
}
|
||||||
obj = _contents_array[index];
|
obj = _contents_array[index];
|
||||||
_count--;
|
_count--;
|
||||||
|
@ -659,9 +681,7 @@ static Class GSInlineArrayClass;
|
||||||
|
|
||||||
if (index >= _count)
|
if (index >= _count)
|
||||||
{
|
{
|
||||||
[NSException raise: NSRangeException format:
|
[self _raiseRangeExceptionForIndex: index];
|
||||||
@"in replaceObjectAtIndex:withObject:, index %d is out of range",
|
|
||||||
index];
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Swap objects in order so that there is always a valid object in the
|
* Swap objects in order so that there is always a valid object in the
|
||||||
|
@ -954,7 +974,7 @@ static Class GSInlineArrayClass;
|
||||||
- (id) objectAtIndex: (unsigned)index
|
- (id) objectAtIndex: (unsigned)index
|
||||||
{
|
{
|
||||||
[NSException raise: NSInternalInconsistencyException
|
[NSException raise: NSInternalInconsistencyException
|
||||||
format: @"attempt to use uninitialised array"];
|
format: @"Attempt to use uninitialised array"];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -991,7 +1011,7 @@ static Class GSInlineArrayClass;
|
||||||
- (unsigned) count
|
- (unsigned) count
|
||||||
{
|
{
|
||||||
[NSException raise: NSInternalInconsistencyException
|
[NSException raise: NSInternalInconsistencyException
|
||||||
format: @"attempt to use uninitialised array"];
|
format: @"Attempt to use uninitialised array"];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue