Merge pull request #10 from gunyarakun/fix-invalid-return
[cocotron.git] / Foundation / NSException / NSException.m
blob7bc292bad014eeaacc31a4f992756f003328da9a
1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
9 // Original - Christopher Lloyd <cjwl@objc.net>
10 #import <Foundation/NSException.h>
11 #import <Foundation/NSDictionary.h>
12 #import <Foundation/NSString.h>
13 #import <Foundation/NSStringFormatter.h>
14 #import <Foundation/NSRaise.h>
15 #import <Foundation/NSThread-Private.h>
16 #import <Foundation/NSObjCRuntime.h>
17 #import <Foundation/NSDebug.h>
18 #import <Foundation/NSRaiseException.h>
19 #include <stdio.h>
21 NSString * const NSGenericException=@"NSGenericException";
22 NSString * const NSInvalidArgumentException=@"NSInvalidArgumentException";
23 NSString * const NSRangeException=@"NSRangeException";
25 NSString * const NSInternalInconsistencyException=@"NSInternalInconsistencyException";
26 NSString * const NSMallocException=@"NSMallocException";
28 NSString * const NSParseErrorException=@"NSParseErrorException";
29 NSString * const NSInconsistentArchiveException=@"NSInconsistentArchiveException";
31 @implementation NSException
33 +(void)raise:(NSString *)name format:(NSString *)format,... {
34    va_list  arguments;
36    va_start(arguments,format);
38    return [self raise:name format:format arguments:arguments];
41 +(void)raise:(NSString *)name format:(NSString *)format arguments:(va_list)arguments {
42    [[self exceptionWithName:name
43      reason:NSStringWithFormatArguments(format,arguments) userInfo:nil] raise];
46 -initWithName:(NSString *)name reason:(NSString *)reason
47   userInfo:(NSDictionary *)userInfo {
48    _name=[name copy];
49    _reason=[reason copy];
50    _userInfo=[userInfo retain];
51    _callStack=nil;
52    return self;
55 -(void)dealloc {
56    [_name release];
57    [_reason release];
58    [_userInfo release];
59    [_callStack release];
60    NSDeallocateObject(self);
61    return;
62    [super dealloc];
65 +(NSException *)exceptionWithName:(NSString *)name reason:(NSString *)reason
66   userInfo:(NSDictionary *)userInfo {
67    return [[[self allocWithZone:NULL] initWithName:name reason:reason userInfo:userInfo] autorelease];
70 -(NSString *)description {
71    return _reason;
74 -copyWithZone:(NSZone *)zone {
75    return [self retain];
78 -initWithCoder:(NSCoder *)coder {
79    NSUnimplementedMethod();
80    return self;
83 -(void)encodeWithCoder:(NSCoder *)coder {
84    NSUnimplementedMethod();
87 -(void)raise {
88    if(NSDebugEnabled){
89     NSCLog("RAISE %s",[[self description] UTF8String]);
90     return;
91    }
92    [_callStack release];
93    _callStack=[[NSThread callStackReturnAddresses] retain];
94    objc_exception_throw(self);
97 -(NSString *)name {
98    return _name;
101 -(NSString *)reason {
102    return _reason;
105 -(NSDictionary *)userInfo {
106    return _userInfo;
109 -(NSArray *)callStackReturnAddresses {
110    return _callStack;
113 @end