Example #1
0
 def _unCatcher(error):
     '''(INTERNAL) Default handler for I{uncaught} C{ObjC/NSExceptions}
        wrapped as an L{NSExceptionError}.
     '''
     logf('handling %s', error, nl=1)
     _SIGraise(_signal.SIGABRT)
     return error  # throw error in case _SIGraise failed
Example #2
0
 def _SIGhandler(sig, frame):  # PYCHOK unused
     '''(INTERNAL) Handler for the C{signal}s enabled by C{fault}.
     '''
     logf('traceback (most recent call last):')
     for t in _NL_.join(traceback.format_stack(frame)).split(_NL_):
         if t:
             logf(t)
     _bye(_SIGname(sig))
Example #3
0
def _bye(name):
    '''(INTERNAL) Time to go ...
    '''
    logf('%s(%s) %s %s %s',
         exiting.__name__,
         _exiting,
         'from',
         name,
         'handler',
         nl=1,
         nt=1)
    if _exiting < 0:
        os._exit(-_exiting)  # force exit
    else:
        sys.exit(_exiting)
Example #4
0
    def _handler(nsException):
        e = NSExceptionError(ObjCInstance(nsException))
        if log:
            s = e.reason or _not_given_
            logf('uncaught ObjC/%s: %s', e.name, s, nl=1)
            logf('datetime %s (%s)', e.datetime, e.versionstr)
            if e.info:
                logf('info: %s', e.info)
            logf('callstack (most recent last):')
            for s in e.callstack:
                logf('  %s', s)  # argv0=_NN_, nt=1

        r = handler(e)
        if r is e or raiser:
            raise e
        elif isinstance(r, int):
            exiting(r)

        _bye(handler.__name__)
Example #5
0
        raise RuntimeError('no %s' % (setUncaughtExceptionHandler.__name__, ))
    return h  # previous


# enable like Python 3.3+
if _PY_FH and not is_enabled():
    enable()

__all__ += _ALL_DOCS(disable, enable, exiting, is_enabled, SIGs_enabled)

if __name__ == '__main__':

    if is_enabled() and '-X' in sys.argv[1:]:
        # test fault handling
        enable(sys.stdout)
        logf('%s: %s', SIGs_enabled.__name__, SIGs_enabled())

        from pycocoa.nstypes import NSColor
        r = NSColor.redColor()
        c = r.cyanComponent()  # bye ...

    elif _PY_FH and '-raise' in sys.argv[1:]:
        # throw an ObjC/NSException and catch it
        from pycocoa.nstypes import nsRaise
        logf('%s ...', nsRaise.__name__)

        nsRaise(reason='testing', _PY_FH=_PY_FH)

    elif _PY_FH and '-try' in sys.argv[1:]:
        # throw an ObjC/NSException, have the handler
        # raise the NSExceptionError and then try to