Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: rrc1962 on May 29, 2016, 08:48:05 PM

Title: Capturing errors
Post by: rrc1962 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.
Title: Re: Capturing errors
Post by: bob_at_pmdx 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 );

Bob
Title: Re: Capturing errors
Post by: rrc1962 on May 29, 2016, 10:47:21 PM
Yes, but how do I capture the actual runtime error that caused to script to fail?