Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (42 sloc) 1.404 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
//
// NSException+GBException.m
// appledoc
//
// Created by Tomaz Kragelj on 23.7.10.
// Copyright (C) 2010, Gentle Bytes. All rights reserved.
//

#import "NSException+GBException.h"

@interface NSException (GBExceptionPrivate)

+ (NSString *)reasonWithError:(NSError *)error message:(NSString *)message;

@end

#pragma mark -

@implementation NSException (GBException)

+ (void)raise:(NSString *)format, ... {
va_list args;
va_start(args, format);
[self raise:@"AppledocException" format:format arguments:args];
va_end(args);
}

+ (void)raise:(NSError *)error format:(NSString *)format, ... {
NSString *message = nil;
if (format) {
va_list args;
va_start(args, format);
message = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
va_end(args);
}

NSString *reason = [self reasonWithError:error message:message];
[self raise:reason];
}

+ (NSString *)reasonWithError:(NSError *)error message:(NSString *)message {
NSInteger code = [error code];
NSString *domain = [error domain];
NSString *description = [error localizedDescription];
NSString *reason = [error localizedFailureReason];

NSMutableString *result = [NSMutableString string];
if (message) [result appendFormat:@"%@\n", message];
[result appendFormat:@"Error: %@, code %i: %@\n", domain, code, description];
if (reason) [result appendFormat:@"Reason: %@", reason];
return result;
}

@end
Something went wrong with that request. Please try again.