home *** CD-ROM | disk | FTP | other *** search
- -- 2000.02.26
- -- Clive Green <clivegreen@atlas.co.uk>
-
- ------------------------------------------------------------------------------------------------------
-
- -- This parent script creates an object and assigns it to a Lingo property called the alertHook -
- -- so named because it provides a way to capture Lingo error alerts.
-
- ------------------------------------------------------------------------------------------------------
-
- -- declare properties:
- property main -- main code object
- property errors -- a list of error codes with messages
-
- ------------------------------------------------------------------------------------------------------
-
- on new me,L
-
- -- (1) extract and check arguments:
-
- -- check for a parameter list:
- if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"errorManager:new"]
-
- -- a reference to the parent codebase is REQUIRED:
- main = L[#main]
- if (ilk(main) <> #instance) then return [#error:#noMainObjectSupplied, #msg:"errorManager:new"]
-
- --------------------
-
- -- (2) obtain listing of error messages:
- dm = main.getDataManager()
- eL = dm.getData([set:#errorListing])
-
- -- confirm listing was obtained:
- if ilk(eL) <> #propList then return [#error:#noErrorListingObtained, #msg:"errorManager:new"]
- errors = eL
-
- --------------------
-
- -- (3) divert error messages from Lingo:
- me.setAlertHook(1)
-
- --------------------
-
- -- just pass back my address:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on setAlertHook me,n
-
- -- set/cancel lingo error alert diversion according to the toggle value passed:
- if n = 1 then v = me
- else v = 0
-
- the alertHook = v
-
- ----------------------------------------------------------------------------------------------------
-
- on error me,eL
-
- -- eL represents an error data package - extract and check its elements:
- if ilk(eL) <> #propList then eL = [#error:#e1001]
-
- -- attempt obtain errorCode symbol and message:
- e = eL[#error]
- m = eL[#msg]
- if voidP(e) then e = #e1002
- else if not symbolP(e) then e = #e1003
-
- -- attempt to extract the data for errorCode e:
- dL = errors[e]
-
- -- if no data for error e was listed, use the errorCode supplied as the error name, with message
- -- (if any )supplied:
- if ilk(dL) <> #propList then dL = [#error:e, #msg:m]
-
- -- extract errorName:
- n = dL[#error]
-
- -- only use native message for error e (if any) when no msg string has been explicitly supplied:
- if not stringP(m) then m = dL[#msg]
-
- -- the errorCode and errorName will match if the former wasn't a listed error;
- --if so, amend the error code to indicate this:
- if e = n then e = #applicationError
-
- --------------------
-
- -- combine the errorCode and errorName:
- e = "#" & e & ": #" & n
-
- -- pass this information to my alertHook handler:
- return me.alertHook(e,m)
-
- ----------------------------------------------------------------------------------------------------
-
- on alertHook me,e,m
-
- -- VERY rudimentary lingo error handling -
- -- this is primarily intended to avoid lingo alerts:
-
- -- put your error handling code here:
- put e & RETURN & m
-
- -- pretend everything is lovely ...
- return 1
-
- ----------------------------------------------------------------------------------------------------