Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Nested try catch
Message
From
28/11/2009 12:54:25
 
 
To
28/11/2009 12:27:50
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01436785
Message ID:
01436831
Views:
59
>>Hi,
>>Should work.
>>Are you saying that the Throw in retParm() fires but that it's not caught in the completewhere func?
>Yes
>
>>IAC, as the code stands, the TRY/CATCH block in retParm() is redundant since you're not handling the exception in any meaningful way.
>That is the point. I want to handle the error in the completewhere() method. My interpretation of the docs says that throw will throw the error to the calling method's error handler????

It should. But it you only want to handle it in the calling method that should happen automatically without needing to specifically CATCH and THROW.. Where does the execution path in your code vary from this:
SET STEP ON
=completewhere();

FUNCTION completewhere()
TRY
  retParm()
CATCH TO loError
  =MESSAGEBOX("retParm() Caught")
ENDTRY
TRY
  retParm2()
CATCH
  =MESSAGEBOX("retParm2() Caught")
ENDTRY
ENDFUNC

FUNCTION retParm()
TRY
  ERROR 1
CATCH TO loError
  MESSAGEBOX("Catch in retParm()")
  THROW loError
ENDTRY
ENDFUNC

FUNCTION retParm2()
ERROR 1
ENDFUNC
>
>>
>>>The error does not throw forward. I would like the completewhere() method to catch the error so I can run the getReqiredParms() method. That is not happening.
>>>>What seems to be a problem?
>>>>>
>>>>>I am trying to get a nested try catch to work using throw with little success. I am trying to get the retParm() method to throw an error and have the completewhere() method catch the error. Is this possible?
>>>>>
>>>>>Thanks.
>>>>>
>>>>>Here is the code
>>>>>
>>>>>	FUNCTION completewhere()
>>>>>		LOCAL llRet 
>>>>>		llRet = .t.
>>>>>		TRY 
>>>>>			this.oparm = this.oParmObj.retparm()
>>>>>		CATCH TO loError 
>>>>>                      * catch the error here and run the method below.
>>>>>			this.getReqiredParms()
>>>>>		FINALLY 		
>>>>>			this.oParmObj.removeall()
>>>>>		ENDTRY 
>>>>>		return llRet 
>>>>>	ENDFUNC
>>>>>
>>>>>	FUNCTION retParm()
>>>>>		LOCAL loRet , loError
>>>>>		loRet = CREATEOBJECT("empty")
>>>>>		TRY 
>>>>>			FOR lnx = 1 TO this.count 
>>>>>				ADDPROPERTY(loRet,this.aitems[lnx,2],this.aitems[lnx,1])
>>>>>			NEXT 
>>>>>		CATCH TO loError 
>>>>>                      * error occurs and throw the error to  completewhere()
>>>>>			THROW loError
>>>>>		FINALLY
>>>>>
>>>>>		ENDTRY
>>>>>		return loRet 
>>>>>	ENDFUNC
>>>>>
>>>>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform