In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

TRY/CATCH

Xailer professional forum in English
Responder
Nick Hilder
Mensajes: 328
Registrado: Mar Nov 21, 2006 2:10 am

TRY/CATCH

Mensaje por Nick Hilder »

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
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9469
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

TRY/CATCH

Mensaje por ignacio »

Nick,
TRY-CATCH it should be used to CATCH errors, not to generate new ones. At
least, that is my opinion, but maybe I am wrong. I suggest the following:
TRY
Your code ...
CATCH oError
MsgAlert( oError:Description + ". Process aborted.", "Run-time error" )
END
In case you want to throw your own errors inside te TRY-CATCH scope section
is perfect to use the function Throw( oError ).
BTW I also suggest to change the property lDisplayErrors on the datasource
and/or the dataset to false and the property lBreakOnErrors to .T. Take a
look to this article on our blog: http://xailer.info/eng/?p=5
Regards,
--
Ignacio Ortiz de Zúñiga
[Soporte Xailer]
[Xailer support]
"Nick Hilder" <nick_n0_spam_atcapsol.com.au> escribió en el mensaje
news:[email=48571227@ozsrv2.ozlan.local...]48571227@ozsrv2.ozlan.local...[/email]
> 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
>
Ignacio Ortiz de Zúñiga
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
NoName
Mensajes: 531
Registrado: Vie Feb 03, 2006 7:27 pm

TRY/CATCH

Mensaje por NoName »

Nick,
TRY-CATCH it should be used to CATCH errors, not to generate new ones. At
least, that is my opinion, but maybe I am wrong. I suggest the following:
TRY
Your code ...
CATCH oError
MsgAlert( oError:Description + ". Process aborted.", "Run-time error" )
END
In case you want to throw your own errors inside te TRY-CATCH scope section
is perfect to use the function Throw( oError ).
BTW I also suggest to change the property lDisplayErrors on the datasource
and/or the dataset to false and the property lBreakOnErrors to .T. Take a
look to this article on our blog: http://xailer.info/eng/?p=5
Regards,
--
Ignacio Ortiz de Zúñiga
[Soporte Xailer]
[Xailer support]
"Nick Hilder" <nick_n0_spam_atcapsol.com.au> escribió en el mensaje
news:[email=48571227@ozsrv2.ozlan.local...]48571227@ozsrv2.ozlan.local...[/email]
> 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
>
Nick Hilder
Mensajes: 328
Registrado: Mar Nov 21, 2006 2:10 am

TRY/CATCH

Mensaje por Nick Hilder »

Hi Ignacio
Thanks for the explaination, I had alook at the article you suggested
I work a bit in C# and sort of see the Error() object as an exception, is
this wrong?
I think what I'm trying to deal with are actually 2 seperate things.
1. Programming Errors, for example if I referenced a property that doesn't
exist, or any error that I'm not in control of, like an Open error on a
dataset
2. Application errors, for example I check to make sure a as I read a file I
make sure the structure is correct. If it's not, I throw an error.
Everything I do is using objects. so if a read inside a object fails, that
object throws an error, this is the correct way of programming, unless I'm
wrong? (I'm no gun programmer )
Based on what you have said so far, for item 1, I should just catch the
runtime error and then display it.
For 2, I should use my own version throw, like I have, does this sound ok
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
Having said all that, I have 2 questions
in 1, after I have caught the error and displayed a message box to the user,
how to do I kill that app, if I use Throw it maybe caught higher up the
chain of Try/Catch's
in 2, what is this Eval( ErrorBlock(), HB_QWith() ) actually doing?
A note on your suggestion , lBreakOnErrors is actually lAbortOnErrors BTW
Is there an easy way to tell if the error that I'm catching is a programming
error , like message not found , or a runtime error like a database not
opening.
Does the System Code tell me this maybe? Is there a range I can check for?
Thanks for your help
Nick
"Ignacio Ortiz de Zúñiga" <NoName@xailer.com> wrote in message
news:48576615$[email=1@ozsrv2.ozlan.local...]1@ozsrv2.ozlan.local...[/email]
> Nick,
>
> TRY-CATCH it should be used to CATCH errors, not to generate new ones. At
> least, that is my opinion, but maybe I am wrong. I suggest the following:
>
> TRY
> Your code ...
> CATCH oError
> MsgAlert( oError:Description + ". Process aborted.", "Run-time error" )
> END
>
> In case you want to throw your own errors inside te TRY-CATCH scope
> section is perfect to use the function Throw( oError ).
>
> BTW I also suggest to change the property lDisplayErrors on the datasource
> and/or the dataset to false and the property lBreakOnErrors to .T. Take a
> look to this article on our blog: http://xailer.info/eng/?p=5
>
> Regards,
>
> --
> Ignacio Ortiz de Zúñiga
> [Soporte Xailer]
> [Xailer support]
>
>
> "Nick Hilder" <nick_n0_spam_atcapsol.com.au> escribió en el mensaje
> news:[email=48571227@ozsrv2.ozlan.local...]48571227@ozsrv2.ozlan.local...[/email]
>> 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
>>
>
>
Nick Hilder
Mensajes: 328
Registrado: Mar Nov 21, 2006 2:10 am

TRY/CATCH

Mensaje por Nick Hilder »

Hi Ignacio
Thanks for the explaination, I had alook at the article you suggested
I work a bit in C# and sort of see the Error() object as an exception, is
this wrong?
I think what I'm trying to deal with are actually 2 seperate things.
1. Programming Errors, for example if I referenced a property that doesn't
exist, or any error that I'm not in control of, like an Open error on a
dataset
2. Application errors, for example I check to make sure a as I read a file I
make sure the structure is correct. If it's not, I throw an error.
Everything I do is using objects. so if a read inside a object fails, that
object throws an error, this is the correct way of programming, unless I'm
wrong? (I'm no gun programmer )
Based on what you have said so far, for item 1, I should just catch the
runtime error and then display it.
For 2, I should use my own version throw, like I have, does this sound ok
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
Having said all that, I have 2 questions
in 1, after I have caught the error and displayed a message box to the user,
how to do I kill that app, if I use Throw it maybe caught higher up the
chain of Try/Catch's
in 2, what is this Eval( ErrorBlock(), HB_QWith() ) actually doing?
A note on your suggestion , lBreakOnErrors is actually lAbortOnErrors BTW
Is there an easy way to tell if the error that I'm catching is a programming
error , like message not found , or a runtime error like a database not
opening.
Does the System Code tell me this maybe? Is there a range I can check for?
Thanks for your help
Nick
"Ignacio Ortiz de Zúñiga" <NoName@xailer.com> wrote in message
news:48576615$[email=1@ozsrv2.ozlan.local...]1@ozsrv2.ozlan.local...[/email]
> Nick,
>
> TRY-CATCH it should be used to CATCH errors, not to generate new ones. At
> least, that is my opinion, but maybe I am wrong. I suggest the following:
>
> TRY
> Your code ...
> CATCH oError
> MsgAlert( oError:Description + ". Process aborted.", "Run-time error" )
> END
>
> In case you want to throw your own errors inside te TRY-CATCH scope
> section is perfect to use the function Throw( oError ).
>
> BTW I also suggest to change the property lDisplayErrors on the datasource
> and/or the dataset to false and the property lBreakOnErrors to .T. Take a
> look to this article on our blog: http://xailer.info/eng/?p=5
>
> Regards,
>
> --
> Ignacio Ortiz de Zúñiga
> [Soporte Xailer]
> [Xailer support]
>
>
> "Nick Hilder" <nick_n0_spam_atcapsol.com.au> escribió en el mensaje
> news:[email=48571227@ozsrv2.ozlan.local...]48571227@ozsrv2.ozlan.local...[/email]
>> 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
>>
>
>
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9469
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

TRY/CATCH

Mensaje por ignacio »

Nick,
> I work a bit in C# and sort of see the Error() object as an exception, is
> this wrong?
Of course not. You did not have have any IF clause in your CATCH area to
detect if it was your own throwed error or a system error. That was the
reason why I told you I could not understand why you throw an error on that
place.
I suggest you use the properies oError:subSsytem and oError:genCode to deal
with your own forced errors.
Regards,
--
Ignacio Ortiz de Zúñiga
[Soporte Xailer]
[Xailer support]
"Nick Hilder" <nick_n0_spam_atcapsol.com.au> escribió en el mensaje
news:[email=4858613c@ozsrv2.ozlan.local...]4858613c@ozsrv2.ozlan.local...[/email]
> Hi Ignacio
>
> Thanks for the explaination, I had alook at the article you suggested
>
> I work a bit in C# and sort of see the Error() object as an exception, is
> this wrong?
>
>
>
> I think what I'm trying to deal with are actually 2 seperate things.
>
> 1. Programming Errors, for example if I referenced a property that doesn't
> exist, or any error that I'm not in control of, like an Open error on a
> dataset
>
> 2. Application errors, for example I check to make sure a as I read a file
> I make sure the structure is correct. If it's not, I throw an error.
>
> Everything I do is using objects. so if a read inside a object fails, that
> object throws an error, this is the correct way of programming, unless I'm
> wrong? (I'm no gun programmer )
>
>
> Based on what you have said so far, for item 1, I should just catch the
> runtime error and then display it.
>
> For 2, I should use my own version throw, like I have, does this sound ok
>
>
> 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
>
> Having said all that, I have 2 questions
>
> in 1, after I have caught the error and displayed a message box to the
> user, how to do I kill that app, if I use Throw it maybe caught higher up
> the chain of Try/Catch's
>
> in 2, what is this Eval( ErrorBlock(), HB_QWith() ) actually doing?
>
> A note on your suggestion , lBreakOnErrors is actually lAbortOnErrors BTW
>
> Is there an easy way to tell if the error that I'm catching is a
> programming error , like message not found , or a runtime error like a
> database not opening.
> Does the System Code tell me this maybe? Is there a range I can check for?
>
>
> Thanks for your help
>
> Nick
>
>
>
>
>
>
>
>
> "Ignacio Ortiz de Zúñiga" <NoName@xailer.com> wrote in message
> news:48576615$[email=1@ozsrv2.ozlan.local...]1@ozsrv2.ozlan.local...[/email]
>> Nick,
>>
>> TRY-CATCH it should be used to CATCH errors, not to generate new ones. At
>> least, that is my opinion, but maybe I am wrong. I suggest the following:
>>
>> TRY
>> Your code ...
>> CATCH oError
>> MsgAlert( oError:Description + ". Process aborted.", "Run-time
>> error" )
>> END
>>
>> In case you want to throw your own errors inside te TRY-CATCH scope
>> section is perfect to use the function Throw( oError ).
>>
>> BTW I also suggest to change the property lDisplayErrors on the
>> datasource and/or the dataset to false and the property lBreakOnErrors to
>> .T. Take a look to this article on our blog: http://xailer.info/eng/?p=5
>>
>> Regards,
>>
>> --
>> Ignacio Ortiz de Zúñiga
>> [Soporte Xailer]
>> [Xailer support]
>>
>>
>> "Nick Hilder" <nick_n0_spam_atcapsol.com.au> escribió en el mensaje
>> news:[email=48571227@ozsrv2.ozlan.local...]48571227@ozsrv2.ozlan.local...[/email]
>>> 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
>>>
>>
>>
>
>
Ignacio Ortiz de Zúñiga
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
NoName
Mensajes: 531
Registrado: Vie Feb 03, 2006 7:27 pm

TRY/CATCH

Mensaje por NoName »

Nick,
> I work a bit in C# and sort of see the Error() object as an exception, is
> this wrong?
Of course not. You did not have have any IF clause in your CATCH area to
detect if it was your own throwed error or a system error. That was the
reason why I told you I could not understand why you throw an error on that
place.
I suggest you use the properies oError:subSsytem and oError:genCode to deal
with your own forced errors.
Regards,
--
Ignacio Ortiz de Zúñiga
[Soporte Xailer]
[Xailer support]
"Nick Hilder" <nick_n0_spam_atcapsol.com.au> escribió en el mensaje
news:[email=4858613c@ozsrv2.ozlan.local...]4858613c@ozsrv2.ozlan.local...[/email]
> Hi Ignacio
>
> Thanks for the explaination, I had alook at the article you suggested
>
> I work a bit in C# and sort of see the Error() object as an exception, is
> this wrong?
>
>
>
> I think what I'm trying to deal with are actually 2 seperate things.
>
> 1. Programming Errors, for example if I referenced a property that doesn't
> exist, or any error that I'm not in control of, like an Open error on a
> dataset
>
> 2. Application errors, for example I check to make sure a as I read a file
> I make sure the structure is correct. If it's not, I throw an error.
>
> Everything I do is using objects. so if a read inside a object fails, that
> object throws an error, this is the correct way of programming, unless I'm
> wrong? (I'm no gun programmer )
>
>
> Based on what you have said so far, for item 1, I should just catch the
> runtime error and then display it.
>
> For 2, I should use my own version throw, like I have, does this sound ok
>
>
> 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
>
> Having said all that, I have 2 questions
>
> in 1, after I have caught the error and displayed a message box to the
> user, how to do I kill that app, if I use Throw it maybe caught higher up
> the chain of Try/Catch's
>
> in 2, what is this Eval( ErrorBlock(), HB_QWith() ) actually doing?
>
> A note on your suggestion , lBreakOnErrors is actually lAbortOnErrors BTW
>
> Is there an easy way to tell if the error that I'm catching is a
> programming error , like message not found , or a runtime error like a
> database not opening.
> Does the System Code tell me this maybe? Is there a range I can check for?
>
>
> Thanks for your help
>
> Nick
>
>
>
>
>
>
>
>
> "Ignacio Ortiz de Zúñiga" <NoName@xailer.com> wrote in message
> news:48576615$[email=1@ozsrv2.ozlan.local...]1@ozsrv2.ozlan.local...[/email]
>> Nick,
>>
>> TRY-CATCH it should be used to CATCH errors, not to generate new ones. At
>> least, that is my opinion, but maybe I am wrong. I suggest the following:
>>
>> TRY
>> Your code ...
>> CATCH oError
>> MsgAlert( oError:Description + ". Process aborted.", "Run-time
>> error" )
>> END
>>
>> In case you want to throw your own errors inside te TRY-CATCH scope
>> section is perfect to use the function Throw( oError ).
>>
>> BTW I also suggest to change the property lDisplayErrors on the
>> datasource and/or the dataset to false and the property lBreakOnErrors to
>> .T. Take a look to this article on our blog: http://xailer.info/eng/?p=5
>>
>> Regards,
>>
>> --
>> Ignacio Ortiz de Zúñiga
>> [Soporte Xailer]
>> [Xailer support]
>>
>>
>> "Nick Hilder" <nick_n0_spam_atcapsol.com.au> escribió en el mensaje
>> news:[email=48571227@ozsrv2.ozlan.local...]48571227@ozsrv2.ozlan.local...[/email]
>>> 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
>>>
>>
>>
>
>
Responder