Improve exceptions.
FossilOrigin-Name: 12b5ef483a1f9eae92df83cf8a6aded299ef10dd2972059a36c79d299e676a0d
This commit is contained in:
parent
16dc91b0e7
commit
25c48048a1
8 changed files with 50 additions and 61 deletions
|
@ -9,11 +9,9 @@
|
|||
@property (readonly, copy, nonatomic) OFString *command;
|
||||
#endif
|
||||
|
||||
+ exceptionWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection
|
||||
+ (instancetype)exceptionWithConnection: (PGConnection*)connection
|
||||
command: (OFString*)command;
|
||||
- initWithConnection: (PGConnection*)connection
|
||||
command: (OFString*)command;
|
||||
- initWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection
|
||||
command: (OFString*)command;
|
||||
- (OFString*)command;
|
||||
@end
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
#import "PGCommandFailedException.h"
|
||||
|
||||
@implementation PGCommandFailedException
|
||||
+ exceptionWithClass: (Class)class
|
||||
connection: (PGConnection*)connection
|
||||
command: (OFString*)command
|
||||
+ (instancetype)exceptionWithConnection: (PGConnection*)connection
|
||||
command: (OFString*)command
|
||||
{
|
||||
return [[[self alloc] initWithClass: class
|
||||
connection: connection
|
||||
command: command] autorelease];
|
||||
return [[[self alloc] initWithConnection: connection
|
||||
command: command] autorelease];
|
||||
}
|
||||
|
||||
- initWithClass: (Class)class
|
||||
connection: (PGConnection*)connection
|
||||
command: (OFString*)command
|
||||
- initWithConnection: (PGConnection*)connection
|
||||
command: (OFString*)command
|
||||
{
|
||||
self = [super initWithClass: class
|
||||
connection: connection];
|
||||
self = [super initWithConnection: connection];
|
||||
|
||||
@try {
|
||||
_command = [command copy];
|
||||
|
@ -36,10 +32,8 @@
|
|||
|
||||
- (OFString*)description
|
||||
{
|
||||
return [OFString stringWithFormat:
|
||||
@"A PostgreSQL command in class %@ failed: %s\nCommand: %@",
|
||||
[self inClass], PQerrorMessage([_connection PG_connection]),
|
||||
_command];
|
||||
return [OFString stringWithFormat: @"A PostgreSQL command failed: %@\n"
|
||||
@"Command: %@", _error, _command];
|
||||
}
|
||||
|
||||
- (OFString*)command
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
- (OFString*)description
|
||||
{
|
||||
return [OFString stringWithFormat:
|
||||
@"Establishing a PostgreSQL connection in class %@ failed:\n%s\n"
|
||||
"Parameters: %@", [self inClass],
|
||||
PQerrorMessage([_connection PG_connection]),
|
||||
[_connection parameters]];
|
||||
@"Establishing a PostgreSQL connection failed:\n%@\n"
|
||||
"Parameters: %@", _error, [_connection parameters]];
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -5,15 +5,14 @@
|
|||
@interface PGException: OFException
|
||||
{
|
||||
PGConnection *_connection;
|
||||
OFString *_error;
|
||||
}
|
||||
|
||||
#ifdef OF_HAVE_PROPERTIES
|
||||
@property (readonly, retain, nonatomic) PGConnection *connection;
|
||||
#endif
|
||||
|
||||
+ exceptionWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection;
|
||||
- initWithClass: (Class)class_
|
||||
connection: (PGConnection*)connection;
|
||||
+ (instancetype)exceptionWithConnection: (PGConnection*)connection;
|
||||
- initWithConnection: (PGConnection*)connection;
|
||||
- (PGConnection*)connection;
|
||||
@end
|
||||
|
|
|
@ -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