In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] ("Sisyphus") wrote:
> ----- Original Message ----- > From: "Markus Schneider" <[EMAIL PROTECTED]> > To: <libwin32@perl.org> > Sent: Tuesday, October 03, 2006 9:36 PM > Subject: Catching Exception from OLE Object > > > > Hi, > > > > I am using Win32OLE to test an application. > > > > For some tests the application throws a "divide by zero" exception, > > due to bugs in the SW. > > > > However, I cannot put this in my test report, since > > Win32::OLE->LastError() does not return the exception. > > In fact, it returns "0". > > > > Anybody can give me a hint how to catch the exception and make > > a nice trace in my report? > > > > From 'perldoc Win32::OLE': > > ------------------------ > Win32::OLE->LastError() > The LastError() class method returns the last recorded OLE > error. This is a dual value like the $! variable: in a numeric > context it returns the error number and in a string context it > returns the error message. > ----------------------- > Hi Rob, the point is that I can catch the OLE exceptions from the application by calling LastError(). The application is calling AfxThrowOleDispatchException. In the beginning, I thought that the HARDWARE Exceptions like "Div by Zero" are forwarded to the OLE interface. At the moment it looks to me, that the application has to catch the HW Exceptions and translate them into OLE Exception. Which can then be printed from the perl script. Thanks a lot , Markus > I guess the solution is therefore to force the return in "string context". > > I have the feeling I should know how to do that ... but it eludes me for the > moment, at least. > > I know a way to force $! into numeric context: > > F:\>perl -e "open(RD, \"not_exist.txt\") or die $!*1" > 2 at -e line 1. > > Whereas, to get $! in string context it's just: > > F:\>perl -e "open(RD, \"not_exist.txt\") or die $!" > No such file or directory at -e line 1. > > Hopefully someone else can provide a *useful* answer :-) > > Cheers, > Rob