Improve exceptions.
FossilOrigin-Name: 12b5ef483a1f9eae92df83cf8a6aded299ef10dd2972059a36c79d299e676a0d
This commit is contained in:
parent
16dc91b0e7
commit
25c48048a1
8 changed files with 50 additions and 61 deletions
|
@ -1,19 +1,24 @@
|
|||
#import "PGException.h"
|
||||
|
||||
@implementation PGException
|
||||
+ exceptionWithClass: (Class)class
|
||||
connection: (PGConnection*)connection
|
||||
+ (instancetype)exceptionWithConnection: (PGConnection*)connection
|
||||
{
|
||||
return [[[self alloc] initWithClass: class
|
||||
connection: connection] autorelease];
|
||||
return [[[self alloc] initWithConnection: connection] autorelease];
|
||||
}
|
||||
|
||||
- initWithClass: (Class)class
|
||||
connection: (PGConnection*)connection
|
||||
- initWithConnection: (PGConnection*)connection
|
||||
{
|
||||
self = [super initWithClass: class];
|
||||
self = [super init];
|
||||
|
||||
_connection = [connection retain];
|
||||
@try {
|
||||
_connection = [connection retain];
|
||||
_error = [[OFString alloc]
|
||||
initWithCString: PQerrorMessage([_connection PG_connection])
|
||||
encoding: OF_STRING_ENCODING_NATIVE];
|
||||
} @catch (id e) {
|
||||
[self release];
|
||||
@throw e;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -21,15 +26,15 @@
|
|||
- (void)dealloc
|
||||
{
|
||||
[_connection release];
|
||||
[_error release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (OFString*)description
|
||||
{
|
||||
return [OFString stringWithFormat:
|
||||
@"A PostgreSQL operation in class %@ failed: %s", [self inClass],
|
||||
PQerrorMessage([_connection PG_connection])];
|
||||
return [OFString stringWithFormat: @"A PostgreSQL operation failed: %@",
|
||||
_error];
|
||||
}
|
||||
|
||||
- (PGConnection*)connection
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue