Question about TRY ... CATCH ... END

Question about TRY ... CATCH ... END

Postby driessen » Thu Nov 13, 2008 11:33 am

Hello,

A question about TRY ... CATCH ... END.

By using this function, one can prevent an error to be happening.

But that also means that no error.log is being made.

Is there a possibility to combine both cases, i.e. making an error.log while using TRY ... CATCH ... END ?

Thanks a lot for any help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby StefanHaupt » Thu Nov 13, 2008 12:18 pm

Michel,

you can decide for your own in the catch statement what to do with the error.

Code: Select all  Expand view
LOCAL  oErr

  TRY
    <do_something>
  CATCH oErr
    if oErr:gencode = ....
      WriteLogFile (oErr:description)
    endif
  END
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby driessen » Thu Nov 13, 2008 1:42 pm

Stefan,

Thanks for your reaction, but I notice some problems.

1. I got an error "no exported method : gencode"
2. I got an error while linking : "Unresolved external symbol : hb_fun_writelogfile".

What now ?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby JC » Thu Nov 13, 2008 1:56 pm

Michel,

With the CATCH, you can use they properties for your error safety:
Code: Select all  Expand view
TRY
   ...
CATCH oError

   msgInfo( oError:SubSystem )
   msgInfo( oError:SubCode )
   msgInfo( oError:Operation )
   msgInfo( oError:Description )
   msgInfo( valToPrg( ::oError:Args ) )

END

With they properties, you can generate you own "err.log" or many others things!!
Peace and lighting!

Júlio César M. Ferreira

FWH 8.10 / xHB 1.1.0 / xDevStudio 0.72 / Pelles C 5.0.1 / SQLLIB 1.9
User avatar
JC
 
Posts: 445
Joined: Thu Feb 21, 2008 11:58 am
Location: Brazil

Postby James Bott » Thu Nov 13, 2008 3:46 pm

Michel,

Use LogFile() instead of WriteLogFile().

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby StefanHaupt » Thu Nov 13, 2008 4:12 pm

Michel,

driessen wrote:1. I got an error "no exported method : gencode"
2. I got an error while linking : "Unresolved external symbol : hb_fun_writelogfile".


oErr:gencode is working here, it´s defined in the errorhandler of xharbour and it´s also working in errorsysw.prg from fwh.

The function WriteLogFile() was just a sample, not a really existing function. Just to show what you can do.

Please try this sample, it´s working fine here. (see also JC´s post)

Code: Select all  Expand view
//----------------------------------------------------------------------------//
FUNCTION CheckErr ()

  LOCAL nLoc, oError

  TRY
    nLoc := "error"/2
  CATCH oError
    msgInfo( oError:gencode )
    msgInfo( oError:SubSystem )
    msgInfo( oError:SubCode )
    msgInfo( oError:Operation )
    msgInfo( oError:Description )
    msgInfo( valToPrg( oError:Args ) )
    quit
  END

RETURN (nLoc)


There are some other values that can be checked, oError:severity, oError:tries, oError:oscode and so on.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby driessen » Thu Nov 13, 2008 5:03 pm

Thanks guys, for your help.

I know what to do now.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

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