Exceptions and Errorcodes

From Apache OpenOffice Wiki
Jump to: navigation, search



UNO interface functions may throw exceptions to communicate an error. Automation objects provide a different error mechanism. First, the IDispatch interface describes a number of error codes (HRESULTs) that are returned under certain conditions. Second, the Invoke function takes an argument that can be used by the object to provide descriptive error information. The argument is a structure of type EXCEPINFO and is used by the bridge to convey exceptions being thrown by the called UNO interface function. In case the UNO method throws an exception the bridge fills EXCEPINFO with these values:

 EXCEPINFO::wCode = 1001
 
 EXCEPINFO::bstrSource = "[automation bridge]"
 
 EXCEPINFO::bstrDescription = type name of the exceptions + the message of the exception (com::sun::star::uno::Exception::message )

Also the returned error code will be DISP_E_EXCEPTION.

Since the automation bridge processes the Invoke call and calls the respective UNO method in the end, there can be other errors which are not caused by the UNO method itself. The following table shows what these errors are and how they are caused.

HRESULT Reason
DISP_E_EXCEPTION
  • UNO interface function or property access function threw an exception and the caller did not provide an EXCEPINFO argument.
  • Bridge error. A ValueObject could not be created when the client called Bridge_GetValueObject.
  • Bridge error. A struct could not be created when the client called Bridge_GetStruct.
  • Bridge error. A wrapper for a UNO type could not be created when the client called Bridge_CreateType.
  • Bridge error. The automation object contains a UNO object that does not support the XInvocation interface. Could be a failure of com.sun.star.script.Invocation service.
  • In JScript was an Array object passed as inout param and the bridge could not retrieve the property "0".
  • A conversion of a VARIANTARG (DISPPARAMS structure) failed for some reason.
  • Parameter count does not tally with the count provided by UNO type information (only when one DISPPARAMS contains <code>VT_DISPATCH). This is a bug. DISP_E_BADPARAMCOUNT should be returned.
DISP_E_NONAMEDARGS
  • The caller provided "named arguments" for a call to a UNO function.
DISP_E_BADVARTYPE
  • Conversion of VARIANTARGs failed.
  • Bridge error: Caller provided a ValueObject and the attempt to retrieve the value failed. This is possibly a bug. DISP_E_EXCEPTION should be returned.
  • A member with the current name does not exist according to type information. This is a bug. DISP_E_MEMBERNOTFOUND should be returned.
  • The argument in Bridge_CreateType was no string or could not be converted into one
DISP_E_BADPARAMCOUNT
  • A property was assigned a value and the caller provided null or more than one arguments.
  • The caller did not provide the number of arguments as required by the UNO interface function.
  • Bridge_CreateType was called where the number of arguments was not one.
DISP_E_MEMBERNOTFOUND
  • Invoke was called with a DISPID that was not issued by GetIDsOfName.
  • There is no interface function (also property access function) with the name for which Invoke is currently being called.
DISP_E_TYPEMISMATCH The called provided an argument of a false type.
DISP_E_OVERFLOW An argument could not be coerced to the expected type. Internal call to XInvocation::invoke resulted in a CannotConvertException<code> being thrown. The field reason has the value OUT_OF_RANGE which means that a given value did not fit in the range of the destination type.
E_UNEXPECTED [2]results from com.sun.star.script.CannotConvertException of XInvocation::invoke with FailReason::UNKNOWN. Internal call to XInvocation::invoke resulted in a com.sun.star.script.CannotConvertException being thrown. The field reason has the value UNKNOWN, which signifies some unknown error condition.
E_POINTER Bridge_GetValueObject or Bridge_GetStruct called and no argument for return value provided.
S_OK Ok.

Return values of IDispatch::GetIDsOfNames:

HRESULT Reason
E_POINTER Caller provided no argument that receives the DISPID.
DISP_E_UNKNOWNNAME There is no function or property with the given name.
S_OK Ok.

The functions IDispatch::GetTypeInfo and GetTypeInfoCount return E_NOTIMPL.

When a call from UNO to an Automation object is performed, then the following HRESULT values are converted to exceptions. Keep in mind that it is determined what exceptions the functions of XInvocation are allowed to throw.

Exceptions thrown by XInvocation::invoke() and their HRESULT counterparts:

HRESULT Exception
DISP_E_BADPARAMCOUNT com.sun.star.lang.IllegalArgumentException
DISP_E_BADVARTYPE com.sun.star.uno.RuntimeException
DISP_E_EXCEPTION com.sun.star.reflection.InvocationTargetException
DISP_E_MEMBERNOTFOUND com.sun.star.lang.IllegalArgumentException
DISP_E_NONAMEDARGS com.sun.star.lang.IllegalArgumentException
DISP_E_OVERFLOW com.sun.star.script.CannotConvertException, reason= FailReason::OUT_OF_RANGE
DISP_E_PARAMNOTFOUND com.sun.star.lang.IllegalArgumentException
DISP_E_TYPEMISMATCH com.sun.star.script.CannotConvertException, reason= FailReason::UNKNOWN
DISP_E_UNKNOWNINTERFACE com.sun.star.uno.RuntimeException
DISP_E_UNKNOWNLCID com.sun.star.uno.RuntimeException
DISP_E_PARAMNOTOPTIONAL com.sun.star.script.CannotConvertException, reason= FailReason::NO_DEFAULT_AVAILABLE

XInvocation::setValue() throws the same as invoke() except for:

HRESULT Exception
DISP_E_BADPARAMCOUNT com.sun.star.uno.RuntimeException
DISP_E_MEMBERNOTFOUND com.sun.star.beans.UnknownPropertyException
DISP_E_NONAMEDARGS com.sun.star.uno.RuntimeException

XInvocation::getValue() throws the same as invoke() except for:

HRESULT Exception
DISP_E_BADPARAMCOUNT com.sun.star.uno.RuntimeException
DISP_E_EXCEPTION com.sun.star.uno.RuntimeException
DISP_E_MEMBERNOTFOUND com.sun.star.beans.UnknownPropertyException
DISP_E_NONAMEDARGS com.sun.star.uno.RuntimeException
DISP_E_OVERFLOW com.sun.star.uno.RuntimeException
DISP_E_PARAMNOTFOUND com.sun.star.uno.RuntimeException
DISP_E_TYPEMISMATCH com.sun.star.uno.RuntimeException
DISP_E_PARAMNOTOPTIONAL com.sun.star.uno.RuntimeException
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages