Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -239,36 +239,40 @@ } - (void)start { if (running == OF_THREAD_RUNNING) - @throw [OFThreadStillRunningException newWithClass: isa]; + @throw [OFThreadStillRunningException newWithClass: isa + thread: self]; [self retain]; if (!of_thread_new(&thread, call_main, self)) { [self release]; - @throw [OFThreadStartFailedException newWithClass: isa]; + @throw [OFThreadStartFailedException newWithClass: isa + thread: self]; } running = OF_THREAD_RUNNING; } - (id)join { if (running == OF_THREAD_NOT_RUNNING || !of_thread_join(thread)) - @throw [OFThreadJoinFailedException newWithClass: isa]; + @throw [OFThreadJoinFailedException newWithClass: isa + thread: self]; running = OF_THREAD_NOT_RUNNING; return retval; } - (void)dealloc { if (running == OF_THREAD_RUNNING) - @throw [OFThreadStillRunningException newWithClass: isa]; + @throw [OFThreadStillRunningException newWithClass: isa + thread: self]; [object release]; [retval release]; [super dealloc]; Index: src/exceptions/OFHashAlreadyCalculatedException.h ================================================================== --- src/exceptions/OFHashAlreadyCalculatedException.h +++ src/exceptions/OFHashAlreadyCalculatedException.h @@ -29,19 +29,21 @@ #ifdef OF_HAVE_PROPERTIES @property (readonly, nonatomic) OFHash *hash; #endif /** + * \param class_ The class of the object which caused the exception * \param hash The hash which has already been calculated * \return A new hash already calculated exception */ + newWithClass: (Class)class_ hash: (OFHash*)hash; /** * Initializes an already allocated hash already calculated exception. * + * \param class_ The class of the object which caused the exception * \param hash The hash which has already been calculated * \return An initialized hash already calculated exception */ - initWithClass: (Class)class_ hash: (OFHash*)hash; Index: src/exceptions/OFThreadJoinFailedException.h ================================================================== --- src/exceptions/OFThreadJoinFailedException.h +++ src/exceptions/OFThreadJoinFailedException.h @@ -14,10 +14,42 @@ * file. */ #import "OFException.h" +@class OFThread; + /** * \brief An exception indicating that joining a thread failed. */ @interface OFThreadJoinFailedException: OFException +{ + OFThread *thread; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFThread *thread; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param thread The thread which could not be joined + * \return A new thread join failed exception + */ ++ newWithClass: (Class)class_ + thread: (OFThread*)thread; + +/** + * Initializes an already allocated thread join failed exception. + * + * \param class_ The class of the object which caused the exception + * \param thread The thread which could not be joined + * \return An initialized thread join failed exception + */ +- initWithClass: (Class)class_ + thread: (OFThread*)thread; + +/** + * \return The thread which could not be joined + */ +- (OFThread*)thread; @end Index: src/exceptions/OFThreadJoinFailedException.m ================================================================== --- src/exceptions/OFThreadJoinFailedException.m +++ src/exceptions/OFThreadJoinFailedException.m @@ -16,12 +16,51 @@ #include "config.h" #import "OFThreadJoinFailedException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFThreadJoinFailedException ++ newWithClass: (Class)class_ + thread: (OFThread*)thread +{ + return [[self alloc] initWithClass: class_ + thread: thread]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + thread: (OFThread*)thread_ +{ + self = [super initWithClass: class_]; + + @try { + thread = [thread_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [thread release]; + + [super dealloc]; +} + - (OFString*)description { if (description != nil) return description; @@ -29,6 +68,11 @@ @"Joining a thread of class %@ failed! Most likely, another thread " @"already waits for the thread to join.", inClass]; return description; } + +- (OFThread*)thread +{ + return thread; +} @end Index: src/exceptions/OFThreadStartFailedException.h ================================================================== --- src/exceptions/OFThreadStartFailedException.h +++ src/exceptions/OFThreadStartFailedException.h @@ -14,10 +14,42 @@ * file. */ #import "OFException.h" +@class OFThread; + /** * \brief An exception indicating that starting a thread failed. */ @interface OFThreadStartFailedException: OFException +{ + OFThread *thread; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFThread *thread; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param thread The thread which could not be started + * \return An initialized thread start failed exception + */ ++ newWithClass: (Class)class_ + thread: (OFThread*)thread; + +/** + * Initializes an already allocated thread start failed exception. + * + * \param class_ The class of the object which caused the exception + * \param thread The thread which could not be started + * \return An initialized thread start failed exception + */ +- initWithClass: (Class)class_ + thread: (OFThread*)thread; + +/** + * \return The thread which could not be started + */ +- (OFThread*)thread; @end Index: src/exceptions/OFThreadStartFailedException.m ================================================================== --- src/exceptions/OFThreadStartFailedException.m +++ src/exceptions/OFThreadStartFailedException.m @@ -16,12 +16,51 @@ #include "config.h" #import "OFThreadStartFailedException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFThreadStartFailedException ++ newWithClass: (Class)class_ + thread: (OFThread*)thread +{ + return [[self alloc] initWithClass: class_ + thread: thread]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + thread: (OFThread*)thread_ +{ + self = [super initWithClass: class_]; + + @try { + thread = [thread_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [thread release]; + + [super dealloc]; +} + - (OFString*)description { if (description != nil) return description; @@ -28,6 +67,11 @@ description = [[OFString alloc] initWithFormat: @"Starting a thread of class %@ failed!", inClass]; return description; } + +- (OFThread*)thread +{ + return thread; +} @end Index: src/exceptions/OFThreadStillRunningException.h ================================================================== --- src/exceptions/OFThreadStillRunningException.h +++ src/exceptions/OFThreadStillRunningException.h @@ -14,10 +14,42 @@ * file. */ #import "OFException.h" +@class OFThread; + /** * \brief An exception indicating that a thread is still running. */ @interface OFThreadStillRunningException: OFException +{ + OFThread *thread; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFThread *thread; +#endif + +/** + * \param class_ The class of the object which caused the exception + * \param thread The thread which is still running + * \return A new thread still running exception + */ ++ newWithClass: (Class)class_ + thread: (OFThread*)thread; + +/** + * Initializes an already allocated thread still running exception. + * + * \param class_ The class of the object which caused the exception + * \param thread The thread which is still running + * \return An initialized thread still running exception + */ +- initWithClass: (Class)class_ + thread: (OFThread*)thread; + +/** + * \return The thread which is still running + */ +- (OFThread*)thread; @end Index: src/exceptions/OFThreadStillRunningException.m ================================================================== --- src/exceptions/OFThreadStillRunningException.m +++ src/exceptions/OFThreadStillRunningException.m @@ -16,12 +16,51 @@ #include "config.h" #import "OFThreadStillRunningException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFThreadStillRunningException ++ newWithClass: (Class)class_ + thread: (OFThread*)thread +{ + return [[self alloc] initWithClass: class_ + thread: thread]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + thread: (OFThread*)thread_ +{ + self = [super initWithClass: class_]; + + @try { + thread = [thread_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [thread release]; + + [super dealloc]; +} + - (OFString*)description { if (description != nil) return description; @@ -29,6 +68,11 @@ @"Deallocation of a thread of type %@ was tried, even though it " @"was still running!", inClass]; return description; } + +- (OFThread*)thread +{ + return thread; +} @end