TRY/CATCH
Publicado: Mar Jun 17, 2008 3:23 am
Hi Gents
I am using TRY CATCH a lot in the app I'm writing.
For example
//Open the Requests table again as a different alias
TRY
WITH OBJECT ::oRequestsCompleteDB := TDbfDataSet():New( )
:oDataSource := AppData:oDataSource
:cProcess := "GENERAL"
:cName := "LLREQUES"
:Alias := "LLCOMPLETE"
:lDisplayErrors := .T.
:lOpen := .T.
:Create()
END
CATCH
::Throw("Failed to open the LLReques.dbf with the Alias LLComplete at:
" + AppData:CapitalPath + AppData:Company)
END
Here's my throw.
//---------------------------------------------------------- --------------------
//Throw a TAppData Exception
//---------------------------------------------------------- --------------------
METHOD Throw( sOperation )
WITH OBJECT ErrorNew()
:Description := "An Exception in an AppData object has occured"
:FileName := "TAppData.prg"
:Operation := sOperation
Eval( ErrorBlock(), HB_QWith() )
END WITH
Return Nil
My throw works, but the problem is that it hides the error.
For example in the code above I have forgetten the c of cAlias. The only way
I can get the run time error is to remove the try catch bloke, then run the
app, see the error, then put it back again. If I don't remove the try catch,
my error handling kicks in and tells me an exception has occured etc.
Any tips on how to stop this happening would be appreciated
Thanks
Nick
I am using TRY CATCH a lot in the app I'm writing.
For example
//Open the Requests table again as a different alias
TRY
WITH OBJECT ::oRequestsCompleteDB := TDbfDataSet():New( )
:oDataSource := AppData:oDataSource
:cProcess := "GENERAL"
:cName := "LLREQUES"
:Alias := "LLCOMPLETE"
:lDisplayErrors := .T.
:lOpen := .T.
:Create()
END
CATCH
::Throw("Failed to open the LLReques.dbf with the Alias LLComplete at:
" + AppData:CapitalPath + AppData:Company)
END
Here's my throw.
//---------------------------------------------------------- --------------------
//Throw a TAppData Exception
//---------------------------------------------------------- --------------------
METHOD Throw( sOperation )
WITH OBJECT ErrorNew()
:Description := "An Exception in an AppData object has occured"
:FileName := "TAppData.prg"
:Operation := sOperation
Eval( ErrorBlock(), HB_QWith() )
END WITH
Return Nil
My throw works, but the problem is that it hides the error.
For example in the code above I have forgetten the c of cAlias. The only way
I can get the run time error is to remove the try catch bloke, then run the
app, see the error, then put it back again. If I don't remove the try catch,
my error handling kicks in and tells me an exception has occured etc.
Any tips on how to stop this happening would be appreciated
Thanks
Nick