Lisp HUG Maillist Archive

Mac equivalent of top-level hook?

For a Windows application all my interfaces inherit from a class which
has a top-level hook[1] that sets up a "catch-all" HANDLER-BIND,
establishes a "global" catch tag and binds a couple of special
variables.  This is a pretty convenient technique.

I understand that there are no top-level hooks on Cocoa and that all
the GUI action happens in one thread which "is already there", but I
was wondering if CAPI hackers use a similar or equivalent technique on
the Mac to "wrap" their code somehow.

Thanks,
Edi.


[1] http://www.lispworks.com/documentation/lw50/CAPRM/html/capiref-157.htm#marker-3919503


Re: Mac equivalent of top-level hook?

On Feb 16, 2008, at 4:09 PM, Edi Weitz wrote:

> For a Windows application all my interfaces inherit from a class which
> has a top-level hook[1] that sets up a "catch-all" HANDLER-BIND,
> establishes a "global" catch tag and binds a couple of special
> variables.  This is a pretty convenient technique.
>
> I understand that there are no top-level hooks on Cocoa and that all
> the GUI action happens in one thread which "is already there", but I
> was wondering if CAPI hackers use a similar or equivalent technique on
> the Mac to "wrap" their code somehow.


When my application initializes (in delivered form only), I set  
*debugger-hook* as a method to handle unexpected errors. Something like:

(when (and (delivered-p) (not (test-p)) (not (debug-p)))
       (setf *debugger-hook* 'unexpected-error-function))



(defun unexpected-error-function (error &optional (debugger-hook nil  
debugger-hook-p))
   (declare (ignore debugger-hook))
   (alert (localize "An unexpected error of type ~a occurred: ~a")  
(type-of error) error)
   (when debugger-hook-p ;we were called from the *debugger-hook- 
function*
     (abort error)))


John DeSoi, Ph.D.





Re: Mac equivalent of top-level hook?

John DeSoi <desoi@pgedit.com> writes:

> When my application initializes (in delivered form only), I set  
> *debugger-hook* as a method to handle unexpected errors. Something like:
>
> (when (and (delivered-p) (not (test-p)) (not (debug-p)))
>       (setf *debugger-hook* 'unexpected-error-function))

I add my debugger-hook function (i.e. capi-e::debugger-hook) to the
process-initial-bindings at build time:

(defun debugger-hook (condition debugger-hook)
  (declare (ignore debugger-hook))
  (collect-backtrace condition)
  (fatal-error-handler condition)
  (invoke-restart (first (compute-restarts condition))))

#+cocoa
(pushnew '(*debugger-hook* . 'debugger-hook) mp:*process-initial-bindings*
         :test 'equal)

-- 
  (espen)


Updated at: 2020-12-10 08:44 UTC