mb_set_error_handler

Previous  Next

 

status_t mb_set_error_handler( mb_interpreter_t* s, mb_error_handler_t pHandler )

 


 

Sets the current error handler.  To remove the handler, supply NULL.  The format of the error handler is defined as

 

typedef void (*mb_error_handler_t)( struct mb_interpreter_t*, enum mb_error_e, char*, WORD, WORD, int );

 

Example

 

/////////////////////////////////////////////////////////////////////////////

//

static void _setup_basic_interpreter( mb_interpreter_t* s, CConsoleCmdLineInfo::RUN_E eEnvironment )

  {

  // MyBASIC Environments defined from 0 (ENV_NONE) to 6 (ENV_MAXGRAPH) so we need to convert

  // If we're not running, set environment to ENV_NONE.  This is the same as running in cmd window

 

  int nEnvironment = eEnvironment > CConsoleCmdLineInfo::eNORUN ? int( eEnvironment ) - 1 : ENV_NONE;

 

  mb_set_environment( s, nEnvironment );

  mb_set_error_handler( s, _on_error );

  mb_set_inputer( s, _getstring );

  mb_set_printer( s, _printstring );

  mb_set_check_keyboard_handler( s, _check_keyboard );

  }

endfunc

 

/////////////////////////////////////////////////////////////////////////////

//

static void _on_error( mb_interpreter_t* s, mb_error_e e, char* m, unsigned short row, unsigned short col, int abort_code )

  {

  if ( mb_get_environment( s ) == ENV_WINDOWS )

     {

     MB2Console_OnBasicError( s, e, m, row, col, abort_code );

     }

  else

     {

     char* type[2] = { "ERROR", "WARNING" };

 

     if ( SE_NO_ERR != e )

        {

        printf( "%s: %s\nModule: %s,  Line: %d,  Col: %d\n", type[abort_code == MB_FUNC_WARNING], m, s->pModule, row, col );

        }

     endif

     }

  endif

  }

endfunc