How to get a more declarative string for VBScript errors

Go To StackoverFlow.com

2

Just to explain more about the context, this is how to reproduce:

  • Delphi 7 (but perhaps more recent versions as well)
  • Import Type Library "Microsoft VBScript Regular Expressions 5.5"

Write a program around this code:

var
  re:RegExp;
try
  re:=CoRegExp.Create;
  re.Pattern:='(';//is an invalid regex, but see below
  re.Test('');
except
  on e:Exception do
    Caption:=e.ClassName+' '+e.Message;
end;

This will throw an Exception EOleError OLE error 800A139C

It does so because SysErrorMessage returns an empty string on this code and the EOleSysError constructor defaults to the SOleError resource string to return something.

Is there a winapi alternative to SysErrorMessage to get a hold of a better error description? If I google around a bit, the code does stand for a 'missing parentheses' error, but if there is a way I could get a (localized) description from the system, I would prefer using it, over having to add an enumeration of error-description constants to my project.

2012-04-05 22:00
by Stijn Sanders


2

That's a COM error. To get a textual description call GetErrorInfo and then IErrorInfo.GetDescription. But don't be surprised if you don't get anything useful back.

2012-04-05 22:48
by David Heffernan
That entirely depends on the COM object's implementation. Not all COM objects support the IErrorInfo interface, but many do. If you use the safecall calling convention to call the COM object methods, then Delphi automatically calls GetErrorInfo() and raises an EOleException that contains the extra error values from IErrorInfo - Remy Lebeau 2012-04-05 23:52
I've debugged and ComObj.pas' SafeCallError does indeed call GetErrorInfo, but doesn't return SOK. I'm specifically asking for VBScriptRegExp55TLB, but for now it looks like it doesn't support IErrorInfo. Still a decent answer to my question so I'll accept - Stijn Sanders 2012-04-09 20:14
Ads