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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to catch errors?

Status
Not open for further replies.

RedLion

Programmer
Sep 13, 2000
342
NL
Hello,

My question is how to catch errors within VFP class methods?

Is there something like try(), catch() and throw() I know from C++, and if what is the name from it, because I can't find it anywhere?

The problem is when I'm writing a method from a class and I've got a piece of code, that can generate an error I want to catch the error and call the method this.Undo().

With on error this.Undo() it says can't find reference to this, you have to give the name from the object.Undo() instead. But when writing class methods, I don't know how I will call the method. And trapping the error when I use the method isn't handy, because it has automatically to call the undo() method otherwise with programming you can forget to call the undo(), and it isn't nice OOP programmed.

Thanks for your time.

Charl
 
Hi..

1. You can use This.Parent.Undo()
This refers to one level up.
2. But still better method is.... at the form lvel create the undo(). In the class you can use.. ThisForm.Undo()
3. Yet another method.. you can have the MyErrorRoutine in a procedural code and add it to the Main prg at the bottom. So this procedure will become available for all the driven programs/forms by that main.prg. So you can simply put at the top of the same Main.pr... ON ERROR DO MyErrorRoutine WITH whatever error parameters you want to pass.

Hope this helps
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
Thanks Ramani and Weedz for the response.

Sorry Ramani, but Weedz got the points ;-)

Remani, using on error do I did use, but as described it is not usable in a class, because the design of a class has to be a black box, and using on error, and catching it in the main is not the way of OOP programming. But thanks for the response.

Yes Weedz, it is not try and catch, because cMethod from the error method can also give the function name called by the method, but it is usable.

Charl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top