gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

objc native exceptions


From: Richard Frith-Macdonald
Subject: objc native exceptions
Date: Fri, 27 Jun 2008 16:35:26 +0100

I was wondering if there was any good reason why gnustep-make doesn't enable native exceptions by default if the compiler supports it. I think the answer is that we can't readily install a default handler for uncaught exceptions or support NSSetUncaughtExceptionHandler() with the current state of the compiler/runtime as it does not provide us with any API to deal with an exception thrown outside of a @try block.

Would it be OK to add that functionality to the runtime in objc_exception_throw() with two new functions something like this:

typedef void (*uncaught_exception_handler)(id);

static uncaught_exception_handler objc_uncaught_exception_handler = 0;

uncaught_exception_handler      objc_get_uncaught_exception_handler ()
{
  return objc_uncaught_exception_handler;
}

void objc_set_uncaught_exception_handler (uncaught_exception_handler h)
{
  objc_uncaught_exception_handler = h;
}

void
objc_exception_throw (id value)
{
  struct ObjcException *header = calloc (1, sizeof (*header));

  memcpy (&header->base.exception_class, &__objc_exception_class,
          sizeof (__objc_exception_class));
  header->base.exception_cleanup = __objc_exception_cleanup;
  header->value = value;

#ifdef SJLJ_EXCEPTIONS
  _Unwind_SjLj_RaiseException (&header->base);
#else
  _Unwind_RaiseException (&header->base);
#endif

  if (objc_uncaught_exception_handler != 0)
    (*objc_uncaught_exception_handler) (value);

  /* Some sort of unwinding error.  */
  abort ();
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]