Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LogFile - logging errors
#1
Hi All,
I would like to keep a log of errors running in my various macros. I saw in the helpfile the following code

Quote:Register function LogErrors to run when current thread (running macro) ends:
atend LogErrors
...

Function LogErrors:
if(_error.source) ;;macro ended due to an error
str macroname.getmacro(getopt(itemid 3) 1)
str functionname.getmacro(_error.iid 1)
str s.format("Macro %s ended due to an error in %s.[]Error description: %s[]Error line: %s" macroname functionname _error.description _error.line)
LogFile s 1

I am not sure how to implement this. I created the Logerrors function. But when I put the statement


Code:
Copy      Help
atend LogErrors

at the end of a macro that would throw an error, nothing showed up in the logfile (though it did show up in the QM Output window.

Do I need to put the "atend LogErrors" statement at the beginning of the macro (before the error-producing statement? Do I have to define _error somewhere.
I am ambarrassed that these must be basic programming questions. Hopefully will be easy to answer.

Thanks, Stuart
#2
Put atend at the beginning, before an error can be generated.

I made the example easier to understand:
Code:
Copy      Help
;If macro ends due to an error, log the error to qmlog.txt file which is in My Documents\My QM:

;Insert this at the beginning of each macro that needs error logging:
atend LogErrors

;And create function LogErrors:
if(_error.source) ;;macro ended due to an error
,str macroname.getmacro(getopt(itemid 3) 1)
,str functionname.getmacro(_error.iid 1)
,str s.format("Macro %s ended due to an error in %s.[]Error description: %s[]Error line: %s[]" macroname functionname _error.description _error.line)
,LogFile s 1
#3
Thanks!!
Stuart
#4
i would like to use it in my exe, do i have to put attend into every function ?
pi
#5
Only in first function. Functions registered with atend run when thread ends.


Forum Jump:


Users browsing this thread: 1 Guest(s)