Page 1 of 1

Error Trapping - name of the currently executing script?

Posted: Fri Jun 24, 2011 2:53 am
by BarrySumpter
Currently trying to trap error on Android

Trying to setup a standard error trapping for all routines.

Anyone know how to return the name of the currently executing script?

Code: Select all

on mouseUp
   
   --   Answer the short name of me     -- of this control
   --   Answer the short name of this card
   --   Answer the short name of this stack
   --   Answer the currentcard of this stack
   
   Answer the short name of this script
   
   
end mouseUp

Re: Error Trapping - name of the currently executing script?

Posted: Fri Jun 24, 2011 11:51 pm
by Mark
Hi Barry,

Try the executionContext.

Kind regards,

Mark

Re: Error Trapping - name of the currently executing script?

Posted: Sat Jun 25, 2011 12:26 am
by BarrySumpter
Nice!
Thanks for that.

Code: Select all

on mouseUp
   
   Answer the short name of me     -- of this control
   Answer the short name of this card
   Answer the short name of this stack
   Answer the currentcard of this stack
   
  -- --Answer the name of the script --of me
   --Answer the name of the executionContext
   
   local tHandler
   
   answer executionContexts
   
   put executionContexts into tHandler
   answer item -2 of line -1 of tHandler
   
   
   put item -2 of line -1 of the executionContexts into tHandler
   --answer "An error occurred in the handler: " & tHandler
   
end mouseUp

Re: Error Trapping - name of the currently executing script?

Posted: Sat Jun 25, 2011 12:30 am
by BarrySumpter
Nice!
Thanks for that.

Code: Select all

on mouseUp
   
   Answer the short name of me     -- of this control
   Answer the short name of this card
   Answer the short name of this stack
   Answer the currentcard of this stack
   
  -- --Answer the name of the script --of me
   --Answer the name of the executionContext
   
   local tHandler
      -- answer executionContexts
      put item -2 of line -1 of the executionContexts into tHandler
      answer "An error occurred in the handler: " & tHandler
   
end mouseUp
Is there anyway to enumerate this structure?
i.e. - Important: The value of the executionContexts may be changed in future versions of LiveCode

Sometimes there are hidden or special MessageBox keywords that allow us to display structures.
I'd just like to be able to know the item names of the executionContexts content.

oops - just found this:
Value
The executionContexts is similar to a call stack, it consists of a list of contexts, one per line, with the most recent context at the end.

Each context is a string of the form:
<object-long-id>,<handler-name>,<line-number>

button id 1003 of card id 1002 of stack "C:/LiveCode/ErrorTrapping.livecode",mouseUp,17

object-long-id = button id 1003 of card id 1002 of stack "C:/LiveCode/ErrorTrapping.livecode"
handler-name = mouseUp
line-number = 17

is there a way to pull out the Name of button id 1003 and the Name of button id 1003?

Code: Select all

 Answer the short name of me     -- of this control
   Answer the short name of this card
   Answer the short name of this stack
yeah OK getting circular redundancy here in my thinking. LOL

Re: Error Trapping - name of the currently executing script?

Posted: Sat Jun 25, 2011 3:59 am
by jacque
The executionContext isn't going away any time soon, it's been around forever with the same warning. I think the IDE itself still uses it.
is there a way to pull out the Name of button id 1003
Um... "the name of btn id 1003", or if you prefer, "the short name of btn id 1003". :)