I have an ocx that can sometimes cause an “internal application error” when calling one of it’s methods in vfp9.
I’ve tried using on error and try/catch. For both, instead of getting the error, I get the Microsoft Visual ForPro has encountered a problem and needs to close…. Send Error Report/Don’t Send dialog.
This is what my code looks like.
on error code (note that I never see the wait window):
LOCAL lcOnError
PUBLIC glErrorResult
glErrorResult = .F.
lcOnError = ON('ERROR')
ON ERROR glErrorResult = .T.
This.oOCXControl.Method()
IF glErrorResult
WAIT WINDOW 'error'
ENDIF
ON ERROR &lcOnError
RELEASE glErrorResult
try/catch code (again, I never see the wait window):
Local oError as Exception
Try
This.oOCXControl.Method()
Catch to oError When .T.
WAIT WINDOW 'error'
EndTry
Is there anything else I could try to handle the error to prevent my app crashing?
So you have a misbehaving OCX control. I’ll assume you’ve already considered options like replacing it with another vendor’s control, or checking for updates. As far as being able to handle the error, I’m not aware of anything you can do that you haven’t already tried. It sounds like the control is such a deviant it is destroying VFP’s ability to continue executing.
Consider how you’re using the control and look for places where you may be breaking the manufacturer’s rules. Especially look for places where you might be encouraging the control to leak memory. Odds are there is a problem building in the control that finally bursts when hitting this line of code.
For example, I had an experience with an old grid control that has certain memory limits. If trying to add too many items to the grid, it didn’t throw an error, instead it just appeared to leak memory into VFP’s processing space and would eventually take the app down. The simple answer was to not try to add a ton of items to the grid.