FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Catching HB_CompileFromBuf() errors
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Catching HB_CompileFromBuf() errors
Posted: Mon Apr 02, 2018 03: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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Catching HB_CompileFromBuf() errors
Posted: Mon Apr 02, 2018 03: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 (fw): Select all Collapse
   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 (fw): Select all Collapse
      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

Continue the discussion