Catching HB_CompileFromBuf() errors

Catching HB_CompileFromBuf() errors

Postby Antonio Linares » Mon Apr 02, 2018 3:14 am

Its been a long time since this conversation happened in the Harbour development group:

https://groups.google.com/d/msg/harbour-devel/WFnOTGO91gk/RdLiu_JyAWYJ

Today I tried to understand Przemek's words again:
Such redirection should be implemented using GT API
because it will in all cases, is portable and much simpler.
Anyhow it's still not necessary because we have PRG API for it
so it's enough to catch RTE.


And after carefully reviewing Przemek's source code, I found the right way to do it. There is an undocumented second parameter than when specified as .T. it generates RTE (run time errors) that we can easily catch:

ErrorBlock( { | o | MsgInfo( o:Description ), DoBreak() } )
oHrb = HB_CompileFromBuf( cCode, .T., "-n" ) // The .T. does the magic :-)

better later than never ;-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Catching HB_CompileFromBuf() errors

Postby Antonio Linares » Mon Apr 02, 2018 3:29 am

How I discovered it:

function HB_CompileFromBuf() is declared in c:\harbour\src\compiler\hbcmplib.c and it makes this call:

hb_compGenArgList( 2, hb_pcount(), &argc, &argv, &pIncItem, &pOpenFunc, &pMsgFunc );

Notice the 2. In hb_compGenArgList() we find this code:
Code: Select all  Expand view  RUN
  if( pMsgFunc )
   {
      *pMsgFunc = NULL;
      if( HB_ISLOG( iFirst ) )
      {
         if( hb_parl( iFirst ) )
            *pMsgFunc = s_pp_msg;
         ++iFirst;
      }
   }


Which means: If the second parameter (the number 2) is logical and it is true, then s_pp_msg is used to route the compiler msgs.

And from s_pp_msg() the runtime error is created:
Code: Select all  Expand view  RUN
     pError = hb_errRT_New( ES_ERROR, "COMPILER", 1001, ( HB_ERRCODE ) iValue,
                             szMsgBuf, szLine, 0 /*OsCode*/, EF_NONE );
      hb_errLaunch( pError );
      hb_errRelease( pError );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 68 guests