diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-03-19 15:48:33 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-03-21 09:19:56 +0100 |
commit | 296f39567b49d6edb054648e7e633ac0bb7111e1 (patch) | |
tree | 4325f19967c19e0f016dded522bd0f0c4a555ab5 /sfx2 | |
parent | dd49d1985d3293095fa6e6ce3b2b0d57d5da8c27 (diff) |
devtools: enclose calls with try/catch to handle exceptions
Some calls to UNO objects throw a RuntimeException if they aren't
implemented, so this makes it necessary to enclose calls to with
try/catch to prevent that exceptions propagate all the way to the
top (crashing the application).
Change-Id: I321171052906c4fe531377949a906689d2182771
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112787
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/devtools/ObjectInspectorTreeHandler.cxx | 87 |
1 files changed, 58 insertions, 29 deletions
diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx index 7884bdb4b88a..4e823fec2008 100644 --- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx +++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx @@ -683,48 +683,67 @@ void GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree, if (!maAny.hasValue()) return; - const auto xNameAccess = uno::Reference<container::XNameAccess>(maAny, uno::UNO_QUERY); - if (xNameAccess.is()) + try { - const uno::Sequence<OUString> aNames = xNameAccess->getElementNames(); - for (OUString const& rName : aNames) + const auto xNameAccess = uno::Reference<container::XNameAccess>(maAny, uno::UNO_QUERY); + if (xNameAccess.is()) { - uno::Any aAny = xNameAccess->getByName(rName); - auto* pObjectInspectorNode = createNodeObjectForAny( - u"@" + rName, aAny, SfxResId(STR_PROPERTY_TYPE_IS_NAMED_CONTAINER)); - lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode); + const uno::Sequence<OUString> aNames = xNameAccess->getElementNames(); + for (OUString const& rName : aNames) + { + uno::Any aAny = xNameAccess->getByName(rName); + auto* pObjectInspectorNode = createNodeObjectForAny( + u"@" + rName, aAny, SfxResId(STR_PROPERTY_TYPE_IS_NAMED_CONTAINER)); + lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode); + } } } - - const auto xIndexAccess = uno::Reference<container::XIndexAccess>(maAny, uno::UNO_QUERY); - if (xIndexAccess.is()) + catch (...) { - for (sal_Int32 nIndex = 0; nIndex < xIndexAccess->getCount(); ++nIndex) - { - uno::Any aAny = xIndexAccess->getByIndex(nIndex); - auto* pObjectInspectorNode - = createNodeObjectForAny(u"@" + OUString::number(nIndex), aAny, - SfxResId(STR_PROPERTY_TYPE_IS_INDEX_CONTAINER)); - lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode); - } } - const auto xEnumAccess = uno::Reference<container::XEnumerationAccess>(maAny, uno::UNO_QUERY); - if (xEnumAccess.is()) + try { - uno::Reference<container::XEnumeration> xEnumeration = xEnumAccess->createEnumeration(); - if (xEnumeration.is()) + const auto xIndexAccess = uno::Reference<container::XIndexAccess>(maAny, uno::UNO_QUERY); + if (xIndexAccess.is()) { - for (sal_Int32 nIndex = 0; xEnumeration->hasMoreElements(); nIndex++) + for (sal_Int32 nIndex = 0; nIndex < xIndexAccess->getCount(); ++nIndex) { - uno::Any aAny = xEnumeration->nextElement(); + uno::Any aAny = xIndexAccess->getByIndex(nIndex); auto* pObjectInspectorNode = createNodeObjectForAny(u"@" + OUString::number(nIndex), aAny, - SfxResId(STR_PROPERTY_TYPE_IS_ENUMERATION)); + SfxResId(STR_PROPERTY_TYPE_IS_INDEX_CONTAINER)); lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode); } } } + catch (...) + { + } + + try + { + const auto xEnumAccess + = uno::Reference<container::XEnumerationAccess>(maAny, uno::UNO_QUERY); + if (xEnumAccess.is()) + { + uno::Reference<container::XEnumeration> xEnumeration = xEnumAccess->createEnumeration(); + if (xEnumeration.is()) + { + for (sal_Int32 nIndex = 0; xEnumeration->hasMoreElements(); nIndex++) + { + uno::Any aAny = xEnumeration->nextElement(); + auto* pObjectInspectorNode + = createNodeObjectForAny(u"@" + OUString::number(nIndex), aAny, + SfxResId(STR_PROPERTY_TYPE_IS_ENUMERATION)); + lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode); + } + } + } + } + catch (...) + { + } auto xInvocationFactory = css::script::Invocation::create(mxContext); uno::Sequence<uno::Any> aParameters = { maAny }; @@ -736,10 +755,20 @@ void GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree, if (!xInvocation.is()) return; - const auto xInvocationAccess = xInvocation->getIntrospection(); + auto const& xInvocationAccess = xInvocation->getIntrospection(); + if (!xInvocationAccess.is()) + return; + + uno::Sequence<script::InvocationInfo> aInvocationInfoSequence; + try + { + aInvocationInfoSequence = xInvocation->getInfo(); + } + catch (...) + { + } - const auto aInvocationInfoSequence = xInvocation->getInfo(); - for (auto const& aInvocationInfo : aInvocationInfoSequence) + for (auto const& aInvocationInfo : std::as_const(aInvocationInfoSequence)) { if (aInvocationInfo.eMemberType == script::MemberType_PROPERTY) { |