Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Try... this.error()... and then catch
Message
From
05/05/2004 13:33:52
 
 
To
03/05/2004 15:35:05
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00897769
Message ID:
00901277
Views:
27
Hi Bob,

In my testing of Try/EndTry this statement is kindof true. If a class is defined with code in its Error method and has another method that is wrapped in a Try block, the behavior I've seen ignores the Error event.
....


The interesting thing is that this is reversible:
oTest = CREATEOBJECT("TryEndTryTest1")
CLEAR
TRY
   oTest.RaiseException()
   ?"Next line Exception was handled"
   CATCH TO oX
   ?"Exception Caught"
ENDTRY 

DEFINE CLASS TryEndTryTest1 as Custom
   ADD OBJECT TryMember as TryEndTryMemberTest1

   FUNCTION Error(nError as Number ,cMethod as String, nLine as Number) 
      ?"Object definition Exception handled"
   ENDFUNC 

   FUNCTION RaiseException()
      this.TryMember.RaiseException() && Has exception Handled in outer Try block
   ENDFUNC 
ENDDEFINE 

DEFINE CLASS TryEndTryMemberTest1 as Custom
   FUNCTION Error(nError as Number ,cMethod as String, nLine as Number) 
      ?"Member Object Exception handled"
   ENDFUNC 

   FUNCTION RaiseException()
      Try
         SELECT PDQ && Handled in Outer Try block
      CATCH
         THROW
      ENDTRY 
   ENDFUNC 
ENDDEFINE 

I've had use cases where it would have been nice to have the option to escalate an error to a higher handler from the code in the error method. Being able to do this sure would be a nice feature.


This is one essential feature, a Error() trapping into a TRY/ENDTRY language
must escalade a error to a higher handler.

But VFP strange or bug resources are limitless;
next code escalade to the external handler:
oTest = CREATEOBJECT("TryEndTryTest1")
CLEAR
TRY
   oTest.RaiseException()
   ?"Next line Exception was handled"
   CATCH TO oX
   ?"Exception Caught"
ENDTRY 

DEFINE CLASS TryEndTryTest1 as Custom
   ADD OBJECT TryMember as TryEndTryMemberTest1

   FUNCTION Error(nError as Number ,cMethod as String, nLine as Number) 
      ?"Object definition Exception handled"
   ENDFUNC 

   FUNCTION RaiseException()
      this.TryMember.RaiseException() && Has exception Handled in outer Try block
   ENDFUNC 
ENDDEFINE 

DEFINE CLASS TryEndTryMemberTest1 as Custom
   FUNCTION Error(nError as Number ,cMethod as String, nLine as Number) 
      ?"Member Object Exception handled"
	TRY
	  THROW
	ENDTRY
   ENDFUNC 

   FUNCTION RaiseException()
      SELECT PDQ && Handled in Outer Try block
   ENDFUNC 
ENDDEFINE 
Previous
Reply
Map
View

Click here to load this message in the networking platform