contents   index   previous   next



INVOKING THE DEBUGGER ON AN ERROR

 

It is often desirable to invoke the debugger only if an error occurs in the script so that the user can debug it. You can do this by initializing the debugger connection not when the script starts but rather only when the error occurs. This is done in the seAtErrorFunc callback in the context parameters. You don’t do this in the sePrintErrorFunc found in the same parameters structure. The first callback is called when the error occurs. The script is still executing at the point of the error with the correct variables and call stack for the error. The second function isn’t called until the script terminates with the error, by which time the context of the error is lost.

 

In addition, the other steps of the debugger integration mentioned above must still be completed. The only difference is that you do not call seDbgConnect before executing any scripts but rather only in response to an error. Here is an example seAtErrorFunc taken from ScriptEase Desktop Win32 which demonstrates invoking the debugger at the point of the error:

 

/* This at-error function will, if debugger support is enabled,

 * give the user the option to connect to the debugger to

 * debug the script from the point of the error.

 */

   static SE_CALLBACK( void )

SeAtErrorFunc(secontext se,struct seAtErrorInfo *info)

{

#if SE_DEBUGGER_SUPPORT==1 && defined(__JSE_WIN32__)

 

   /* If this is an untrapped error, debug it at the point

    * of error. Untrapped errors are the ones that will

    * eventually be printed to the screen. We don't

    * debug trapped errors because those are usually

    * used for program flow control with throw/catch.

    */

   if( !seDbgConnected(se) &&

       !info->trapped &&

       MessageBox(0,seGetString(se,SE_RETURN,SE_VALUE,NULL),

                  "Would you like to debug this error?",

                  MB_YESNO)==IDYES

       )

   {

      struct seContextParams *params;

 

      params = seGetContextParams(se);

      params->seOptions |= SE_OPT_DEBUGGER;

 

      if( !seDbgConnect(se,"localhost",SEDBG_STANDARD_PORT,

                        "Scriptease Desktop Win32",NULL) )

      {

         sememcount i;

 

         system("start workshop.exe");

 

         /* Wait 10 seconds checking every 1/10th if

* debugger is ready

*/

         for( i=0;i<100;i++ )

         {

            Sleep(100);

            if( seDbgConnect(se,"localhost",SEDBG_STANDARD_PORT,

                             "Scriptease Desktop Win32",NULL) )

               break;

         }

      }

   }

 

   seDbgAtError(se);

#endif

}


THE SCRIPTEASE DEBUGGER PROTOCOL VERSION 1.0