Hello Guest it is May 14, 2021, 04:00:51 AM

Author Topic: Capturing errors  (Read 1122 times)

0 Members and 1 Guest are viewing this topic.

Capturing errors
« on: May 29, 2016, 08:48:05 PM »
Is there a way to capture and display errors in a button script.  Problem is that when the script fails, it just doesn't do anything as if it never ran.  The reason why it failed would be immensely helpful.
Re: Capturing errors
« Reply #1 on: May 29, 2016, 09:32:23 PM »
Yes, call
     local inst=mc.mcGetInstance();  -- Omit this if you already have done this
    mc.mcCntlSetLastError( inst, "Your error message here" );

That will display a message in the Mach4 status/error line at the bottom of the window, and also in the "History".

Or you can use:

  mc.mcCntlLog(inst, "Your error message");

Which will add an entry to the Mach4 log (view it from the Diagnostics menu, select "Logger").

Disclaimer: I am not at a PC with the Mach API docs.  In the plug-in API, there are two additional parameters in the mcCntlLog() call, the file name and line number.  I don't know if they exist in the Lua version, or if they are optional.  I *think* you can pass NULL and zero for these if you don't want or need them, but I'm not sure.

  mc.mcCntlLog( inst, "Your error message", NULL, 0 );

Re: Capturing errors
« Reply #2 on: May 29, 2016, 10:47:21 PM »
Yes, but how do I capture the actual runtime error that caused to script to fail?