Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

on error is not working?? 2

Status
Not open for further replies.

ron9999

Programmer
Feb 14, 2003
89
AT
I use this code to check if the table is in use:

local llerror
llerror=.f.
lcStlFileName="02155.stk" (it's a dbf)
ON ERROR llerror = .T.
lcStkl= SYS(5)+CURDIR()+'BELEGE\'+ lcStlFileName
SELECT 0
USE &lcStkl EXCLUSIVE ALIAS 'ITEMLIST'
IF llerror
thisform.Caption = "file is in use !!!"
ENDIF

when I step it through
I can see the file was not opend (is not there)
but the error don't trigger llerror
llerror is still .f.

if I make the same procedure in command-window it works

tia
ron
 
Actually, errors thrown by subroutines Are caught by CATCH:

Code:
LOCAL oExc as Exception 
TRY
  DO throwError
CATCH TO oExc
  MESSAGEBOX(oExc.Message+CHR(13);
             +'Proc: '+oExc.Procedure +CHR(13);
             +'Line#: '+TRANSFORM(oExc.LineNo) +CHR(13);
             +'Line: '+oExc.LineContents )
ENDTRY

PROCEDURE throwError
  Whoops!
ENDPROC

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Okay Bill,

maybe I'm wwrong about TRY ... CATCH. But I remember there was acatch with it :). Try to put the throwError procedure in a completely different file.

Bye, Olaf.
 
Hi all.

Doesn't USE dbfname EXCLUSIVE ALIAS 'ITEMLIST' throw an error?

Course, since you don't have errors caught by the system (ON ERROR DO Proc in effect), could be hard to track down.

Guess I'll have to test it myself. I think ITEMLIST is not supposed to be surrounded by quotes.

Regards,

Mike
 
One of the catches with TRY..CATCH is that you can't use ON ERROR in a subroutine to trap errors if that subroutine was called from within a TRY..CATCH block.

On the other hand, the .Error method of an object whose method was called from within a TRY..CATCH Does fire.

IE:
Code:
LOCAL oExc as Exception
TRY
  DO throwError
CATCH TO oExc
  MESSAGEBOX('Caught Exception: '+oExc.Message+CHR(13);
             +'Proc: '+oExc.Procedure +CHR(13);
             +'Line#: '+TRANSFORM(oExc.LineNo) +CHR(13);
             +'Line: '+oExc.LineContents )
ENDTRY
TRY
  loX = create('whatever')
  loX.throwError
CATCH TO oExc
  * This does NOT fire!
  MESSAGEBOX('Caught Exception: '+oExc.Message+CHR(13);
             +'Proc: '+oExc.Procedure +CHR(13);
             +'Line#: '+TRANSFORM(oExc.LineNo) +CHR(13);
             +'Line: '+oExc.LineContents )
ENDTRY


PROCEDURE throwError
  * This next line will throw an exception, which will be Caught above...
  Whoops!
ENDPROC

DEFINE CLASS whatever AS session
  PROCEDURE throwError
    * this next line will cause the .Error event to fire:
    Whoops!
  ENDPROC
  PROCEDURE Error
  LPARAMETERS nError, cMethod, nLine
    * This DOES fire:
    MESSAGEBOX('Error Method: '+oExc.Message+CHR(13);
             +'Proc: '+oExc.Procedure +CHR(13);
             +'Line#: '+TRANSFORM(oExc.LineNo) +CHR(13);
             +'Line: '+oExc.LineContents )
  ENDPROC
ENDDEFINE

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top