[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: @try @catch @finally examples
From: |
Chris Vetter |
Subject: |
Re: @try @catch @finally examples |
Date: |
Wed, 26 Jan 2005 12:34:00 +0100 (MET) |
> -----BEGIN PGP SIGNED MESSAGE-----
> Where can we see examples for these? I cant find a manual anywhere.
Pseudo Code...
@interface FoobarException : NSException
@end
@implementation FoobarException
@end
@interface Foo : NSObject
- (void) doSomething;
- (void) doSomethingElse;
@end
@implementation Foo
- (void) doSomething
{
// do something
if( "something went wrong" )
{
NSException *e;
e = [FoobarException exceptionWithName: @"FoobarException"
reason: @"Something went wrong" userInfo: nil];
@throw e;
}
return;
}
- (void) doSomethingElse
{
// do something else
return;
}
@end
void main(void)
{
Foo *bar;
bar = [[Foo alloc] init];
@try
{
[bar doSomething];
}
@catch(FoobarException *e)
{
printf( "%s: ", [[e name] cString] );
exit(EXIT_FAILURE);
}
// you can add more @catch statements here
@finally
{
[bar doSomethingElse];
}
exit(EXIT_SUCCESS);
}
--
Chris
--
GMX im TV ... Die Gedanken sind frei ... Schon gesehen?
Jetzt Spot online ansehen: http://www.gmx.net/de/go/tv-spot