/* Catch.h          -*-objc-*-
 *
 * catch and throw for Objective-C programs.
 *
 * Copyright Niels Möller <nisse@lysator.liu.se> 1995
 *
 * Freely distributable under the terms and conditions of the
 * GNU General Public License 
 */

#ifndef CATCH_OBJC_H_INCLUDED
#define CATCH_OBJC_H_INCLUDED

#include <StackFrame.h>

/* Catch
 * -----
 *
 * id tag = [Catch new];
 * if (set_catch(tag) == 0)
 *   {
 *     ...
 *     result = ...
 *   }
 * else
 *   result = [tag value]; // Value passed with -throw
 * [tag free];
 *
 *
 * If you have GNUC, you can alternatively use the CATCH macro:
 *
 * id tag = [Frame new];
 * id result = CATCH(tag, {
 *                          body
 *                        });
 * [tag free];
 *
 * which does the same thing. The value of this expression is the
 * same as RESULT above.
 *
 * To pass control to the tag established with Catch, use [tag -throw].
 *
 */

typedef struct
{
  jmp_buf jmp;
} catch_buf;

#define set_catch(buf) setjmp((buf)->jmp)

@interface Catch_common : StackFrame
{
  id result;
  catch_buf where;
}
- (catch_buf *) where;
- (catch_buf *) catch;
@end /* StackFrame */


@interface Catch : Catch_common
- value;
- value: newValue;
- (void) throw: value;
- (void) throwInt: (int) value;
- (void) throw: value1 : (int) value2 free: (BOOL) freeFlag;
@end /* Catch */

@interface CatchError : Catch_common
{
  id errorClass;
}
- (catch_buf *) catch: class;
- errorClass;
- errorClass: class;
- error;
- setError: object;
@end /* CatchError */


#endif CATCH_OBJC_H_INCLUDED
