Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
COMRETURNERROR and Try Catch?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00753449
Message ID:
00753595
Views:
25
>Can anyone illustrate an example of using a Try Catch block along with COMRETURNERROR so an
>error message "bubbles out" of my object, whether it is instanced from the IDE, as part of a
>VFP desktop exe, or a MTDLL? I am having a hrd time getting my head around the concept.

I just put this together. If you run it as is, it shows exceptions bubbling out of a class to a calling program. If you uncomment the Error method, it will show a different style, and if you then compile it into an MTDLL, you'll get yet another. Play with the code, and figure out why I did what I did where -- maybe you'll figure out the stuff I messed up, too. :-)
#DEFINE vfpCRLF CHR(13) + CHR(10)

LOCAL loErr as Exception 

lox = CREATEOBJECT("ThrowTest")
TRY
   lox.BadCall()
CATCH TO loErr
   loCaught = loErr.UserValue
	
   MESSAGEBOX("CAUGHT ERROR" + vfpCRLF + vfpCRLF + ;
      "Error number: " + TRANSFORM(loCaught.ErrorNo) + vfpCRLF + ;
      "Method:       " + TRANSFORM(loCaught.Procedure) + vfpCRLF + ;
      "Line Number:  " + TRANSFORM(loCaught.LineNo) + vfpCRLF + ;
      "Line Contents:" + loCaught.LineContents)
ENDTRY


DEFINE CLASS ThrowTest AS SESSION OLEPUBLIC

*!*	   PROCEDURE ERROR
*!*	      LPARAMETERS nError, cMethod, nLine

*!*	      IF INLIST(_VFP.STARTMODE, 3, 5)
*!*	         COMRETURNERROR("DLL Error Event", ;
*!*                 "ERROR " + TRANSFORM(nError) + " in " + cMethod + ", line " + TRANSFORM(nLine))
*!*	      ELSE
*!*	         MESSAGEBOX("ERROR METHOD" + vfpCRLF + vfpCRLF + ;
*!*	            "Error number: " + TRANSFORM(nError) + vfpCRLF + ;
*!*	            "Method:       " + TRANSFORM(cMethod) + vfpCRLF + ;
*!*	            "Line Number:  " + TRANSFORM(nLine) + vfpCRLF)
*!*	      ENDIF
*!*	   ENDPROC

   PROCEDURE BadCall
      LOCAL loErr AS Exception, loErr2 AS Exception

      TRY
         ERROR 1
      CATCH TO loErr
         IF INLIST(_VFP.STARTMODE, 3, 5)
            THIS.ERROR(loErr.ErrorNo, loErr.PROCEDURE, loErr.LINENO)
         ELSE
            THROW loErr
         ENDIF
      ENDTRY
   ENDPROC
ENDDEFINE
My blog
My consulting page
My home page

Member of the Trim Your Auto-Quote Campaign!
What's another word for thesaurus?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform