/* 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>
#include <Exception.h>
#include <Jumping.h>

#if 0
/* Defined in JMP_BUF.h instead */
typedef struct
{
  jmp_buf jmp;
} catch_buf;

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

@interface Catch_common : StackFrame <Jumping>
{
  id result;
  JMP_BUF where;
}
- (JMP_BUF *) where;
- (JMP_BUF *) catch;
@end /* Catch_common */


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


@interface CatchException : Catch_common
{
  exception_type exceptionType;
}
- (JMP_BUF *) catch: type;
- exceptionType;
- exceptionType: type;
- exception;
- exception: object;
@end /* CatchException */


/* Macros */

#define STARTCATCH(tag) {\
  (tag) = [Catch new]; \
  if (SETJMP(*[(tag) catch])==0) {

#define CATCH(tag) } else {

#define ENDCATCH(tag) } [(tag) free];}

#define CATCH_EXCEPTION(tag, type) {\
  (tag) = [CatchException new]; \
  if (SETJMP(*[(tag) catch: (type)]) == 0) {

#endif CATCH_OBJC_H_INCLUDED
