From ece0729e18b4b306933439d1a329df192fc504d3 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 13 Aug 2024 13:43:25 +0200 Subject: use less exception throwing for flow control Change-Id: Ib376a1bcb75e72d6e5754818a353b0d9c7dbd26d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171851 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sfx2/source/dialog/dinfdlg.cxx | 11 ++++-- sfx2/source/dialog/documentfontsdialog.cxx | 41 ++++++++++++------- sfx2/source/doc/DocumentSigner.cxx | 9 +++-- sfx2/source/doc/docfile.cxx | 15 ++++--- sfx2/source/doc/doctemplates.cxx | 13 +++--- sfx2/source/doc/guisaveas.cxx | 24 +++++------ sfx2/source/doc/objserv.cxx | 5 ++- sfx2/source/doc/objstor.cxx | 46 +++++++++++++--------- sot/source/unoolestorage/xolesimplestorage.cxx | 5 ++- svx/source/smarttags/SmartTagMgr.cxx | 22 +++++++---- .../tbxctrls/StylesPreviewToolBoxControl.cxx | 15 ++++--- svx/source/tbxctrls/tbcontrl.cxx | 5 ++- svx/source/xml/xmleohlp.cxx | 14 ++++--- svx/source/xml/xmlxtimp.cxx | 5 ++- 14 files changed, 140 insertions(+), 90 deletions(-) diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx index 537206b3f98c..d752920ac490 100644 --- a/sfx2/source/dialog/dinfdlg.cxx +++ b/sfx2/source/dialog/dinfdlg.cxx @@ -1294,10 +1294,13 @@ void SfxDocumentPage::Reset( const SfxItemSet* rSet ) { try { - uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY_THROW ); - - xProps->getPropertyValue(u"ImagePreferredDPI"_ustr) >>= nImagePreferredDPI; + uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno::UNO_QUERY ); + if (xFac) + { + uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY ); + if (xProps) + xProps->getPropertyValue(u"ImagePreferredDPI"_ustr) >>= nImagePreferredDPI; + } } catch( uno::Exception& ) { diff --git a/sfx2/source/dialog/documentfontsdialog.cxx b/sfx2/source/dialog/documentfontsdialog.cxx index 281baf5278ed..73918ca059d8 100644 --- a/sfx2/source/dialog/documentfontsdialog.cxx +++ b/sfx2/source/dialog/documentfontsdialog.cxx @@ -60,14 +60,19 @@ void SfxDocumentFontsPage::Reset( const SfxItemSet* ) { try { - uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY_THROW ); - - xProps->getPropertyValue(u"EmbedFonts"_ustr) >>= bEmbedFonts; - xProps->getPropertyValue(u"EmbedOnlyUsedFonts"_ustr) >>= bEmbedUsedFonts; - xProps->getPropertyValue(u"EmbedLatinScriptFonts"_ustr) >>= bEmbedLatinScriptFonts; - xProps->getPropertyValue(u"EmbedAsianScriptFonts"_ustr) >>= bEmbedAsianScriptFonts; - xProps->getPropertyValue(u"EmbedComplexScriptFonts"_ustr) >>= bEmbedComplexScriptFonts; + uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno::UNO_QUERY ); + if (xFac) + { + uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY); + if (xProps) + { + xProps->getPropertyValue(u"EmbedFonts"_ustr) >>= bEmbedFonts; + xProps->getPropertyValue(u"EmbedOnlyUsedFonts"_ustr) >>= bEmbedUsedFonts; + xProps->getPropertyValue(u"EmbedLatinScriptFonts"_ustr) >>= bEmbedLatinScriptFonts; + xProps->getPropertyValue(u"EmbedAsianScriptFonts"_ustr) >>= bEmbedAsianScriptFonts; + xProps->getPropertyValue(u"EmbedComplexScriptFonts"_ustr) >>= bEmbedComplexScriptFonts; + } + } } catch( uno::Exception& ) { @@ -95,13 +100,19 @@ bool SfxDocumentFontsPage::FillItemSet( SfxItemSet* ) { try { - uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY_THROW ); - xProps->setPropertyValue(u"EmbedFonts"_ustr, uno::Any(bEmbedFonts)); - xProps->setPropertyValue(u"EmbedOnlyUsedFonts"_ustr, uno::Any(bEmbedUsedFonts)); - xProps->setPropertyValue(u"EmbedLatinScriptFonts"_ustr, uno::Any(bEmbedLatinScriptFonts)); - xProps->setPropertyValue(u"EmbedAsianScriptFonts"_ustr, uno::Any(bEmbedAsianScriptFonts)); - xProps->setPropertyValue(u"EmbedComplexScriptFonts"_ustr, uno::Any(bEmbedComplexScriptFonts)); + uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno::UNO_QUERY ); + if (xFac) + { + uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY ); + if (xProps) + { + xProps->setPropertyValue(u"EmbedFonts"_ustr, uno::Any(bEmbedFonts)); + xProps->setPropertyValue(u"EmbedOnlyUsedFonts"_ustr, uno::Any(bEmbedUsedFonts)); + xProps->setPropertyValue(u"EmbedLatinScriptFonts"_ustr, uno::Any(bEmbedLatinScriptFonts)); + xProps->setPropertyValue(u"EmbedAsianScriptFonts"_ustr, uno::Any(bEmbedAsianScriptFonts)); + xProps->setPropertyValue(u"EmbedComplexScriptFonts"_ustr, uno::Any(bEmbedComplexScriptFonts)); + } + } } catch( uno::Exception& ) { diff --git a/sfx2/source/doc/DocumentSigner.cxx b/sfx2/source/doc/DocumentSigner.cxx index 88dd7c3c3570..ae2db667ca75 100644 --- a/sfx2/source/doc/DocumentSigner.cxx +++ b/sfx2/source/doc/DocumentSigner.cxx @@ -98,9 +98,12 @@ bool DocumentSigner::signDocument(uno::Reference const& if (bSuccess) { uno::Reference xTransact(xWriteableZipStore, - uno::UNO_QUERY_THROW); - xTransact->commit(); - bResult = true; + uno::UNO_QUERY); + if (xTransact) + { + xTransact->commit(); + bResult = true; + } } } else diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 1674a41131df..c9631f64cbde 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -4676,12 +4676,15 @@ bool SfxMedium::SwitchDocumentToFile( const OUString& aURL ) { try { - uno::Reference< io::XTruncate > xTruncate( pImpl->xStream, uno::UNO_QUERY_THROW ); - xTruncate->truncate(); - if ( xOptStorage.is() ) - xOptStorage->writeAndAttachToStream( pImpl->xStream ); - pImpl->xStorage = xStorage; - bResult = true; + uno::Reference< io::XTruncate > xTruncate( pImpl->xStream, uno::UNO_QUERY ); + if (xTruncate) + { + xTruncate->truncate(); + if ( xOptStorage.is() ) + xOptStorage->writeAndAttachToStream( pImpl->xStream ); + pImpl->xStorage = xStorage; + bResult = true; + } } catch( const uno::Exception& ) {} diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx index 82826eb4c711..b5926871954e 100644 --- a/sfx2/source/doc/doctemplates.cxx +++ b/sfx2/source/doc/doctemplates.cxx @@ -674,11 +674,14 @@ void SfxDocTplService::getTitleFromURL( const OUString& rURL, OUString& aTitle, if ( !aDocType.isEmpty() ) try { - uno::Reference< container::XNameAccess > xTypeDetection( mxType, uno::UNO_QUERY_THROW ); - SequenceAsHashMap aTypeProps( xTypeDetection->getByName( aDocType ) ); - aType = aTypeProps.getUnpackedValueOrDefault( - u"MediaType"_ustr, - OUString() ); + uno::Reference< container::XNameAccess > xTypeDetection( mxType, uno::UNO_QUERY ); + if (xTypeDetection) + { + SequenceAsHashMap aTypeProps( xTypeDetection->getByName( aDocType ) ); + aType = aTypeProps.getUnpackedValueOrDefault( + u"MediaType"_ustr, + OUString() ); + } } catch( uno::Exception& ) {} diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index bcbd7679bef5..8688abd73117 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -225,20 +225,20 @@ public: { try { - uno::Reference< lang::XMultiServiceFactory > xDocSettingsSupplier( xModel, uno::UNO_QUERY_THROW ); - m_xDocumentSettings.set( - xDocSettingsSupplier->createInstance( u"com.sun.star.document.Settings"_ustr ), - uno::UNO_QUERY_THROW ); - - try + uno::Reference< lang::XMultiServiceFactory > xDocSettingsSupplier( xModel, uno::UNO_QUERY ); + if (xModel) { - OUString aLoadReadonlyString( u"LoadReadonly"_ustr ); - m_xDocumentSettings->getPropertyValue( aLoadReadonlyString ) >>= m_bPreserveReadOnly; - m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::Any( bReadOnly ) ); - m_bReadOnlySupported = true; + m_xDocumentSettings.set( + xDocSettingsSupplier->createInstance( u"com.sun.star.document.Settings"_ustr ), + uno::UNO_QUERY ); + if (m_xDocumentSettings) + { + OUString aLoadReadonlyString( u"LoadReadonly"_ustr ); + m_xDocumentSettings->getPropertyValue( aLoadReadonlyString ) >>= m_bPreserveReadOnly; + m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::Any( bReadOnly ) ); + m_bReadOnlySupported = true; + } } - catch( const uno::Exception& ) - {} } catch( const uno::Exception& ) {} diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 26301eb1cb6d..ab43f0482492 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -1839,8 +1839,9 @@ uno::Sequence< security::DocumentSignatureInformation > SfxObjectShell::GetDocum OUString aVersion; try { - uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW ); - xPropSet->getPropertyValue(u"Version"_ustr) >>= aVersion; + uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY ); + if (xPropSet) + xPropSet->getPropertyValue(u"Version"_ustr) >>= aVersion; } catch( uno::Exception& ) { diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index fefea8c2969a..fe00764a6bee 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -1532,8 +1532,9 @@ bool SfxObjectShell::SaveTo_Impl OUString aODFVersion; try { - uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW ); - xPropSet->getPropertyValue(u"Version"_ustr) >>= aODFVersion; + uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY ); + if (xPropSet) + xPropSet->getPropertyValue(u"Version"_ustr) >>= aODFVersion; } catch( uno::Exception& ) {} @@ -1769,9 +1770,10 @@ bool SfxObjectShell::SaveTo_Impl try { - uno::Reference< beans::XPropertySet > xProps( rMedium.GetStorage(), uno::UNO_QUERY_THROW ); - xProps->setPropertyValue(u"MediaType"_ustr, - uno::Any( aDataFlavor.MimeType ) ); + uno::Reference< beans::XPropertySet > xProps( rMedium.GetStorage(), uno::UNO_QUERY ); + if (xProps) + xProps->setPropertyValue(u"MediaType"_ustr, + uno::Any( aDataFlavor.MimeType ) ); } catch( uno::Exception& ) { @@ -1975,8 +1977,9 @@ bool SfxObjectShell::SaveTo_Impl OUString aVersion; try { - uno::Reference < beans::XPropertySet > xPropSet( rMedium.GetStorage(), uno::UNO_QUERY_THROW ); - xPropSet->getPropertyValue(u"Version"_ustr) >>= aVersion; + uno::Reference < beans::XPropertySet > xPropSet( rMedium.GetStorage(), uno::UNO_QUERY ); + if (xPropSet) + xPropSet->getPropertyValue(u"Version"_ustr) >>= aVersion; } catch( uno::Exception& ) { @@ -2289,15 +2292,17 @@ bool SfxObjectShell::ConnectTmpStorage_Impl( // Get rid of this workaround after issue i113914 is fixed try { - uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY_THROW ); - xBasicLibraries->setRootStorage( xTmpStorage ); + uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY ); + if (xBasicLibraries) + xBasicLibraries->setRootStorage( xTmpStorage ); } catch( uno::Exception& ) {} try { - uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY_THROW ); - xDialogLibraries->setRootStorage( xTmpStorage ); + uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY ); + if (xDialogLibraries) + xDialogLibraries->setRootStorage( xTmpStorage ); } catch( uno::Exception& ) {} @@ -2453,15 +2458,17 @@ bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed, bool bRegisterRecent ) // Get rid of this workaround after issue i113914 is fixed try { - uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY_THROW ); - xBasicLibraries->setRootStorage( xStorage ); + uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY ); + if (xBasicLibraries) + xBasicLibraries->setRootStorage( xStorage ); } catch( uno::Exception& ) {} try { - uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY_THROW ); - xDialogLibraries->setRootStorage( xStorage ); + uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY ); + if (xDialogLibraries) + xDialogLibraries->setRootStorage( xStorage ); } catch( uno::Exception& ) {} @@ -4137,9 +4144,12 @@ bool SfxObjectShell::GenerateAndStoreThumbnail(bool bEncrypted, const uno::Refer if (xStream.is() && WriteThumbnail(bEncrypted, xStream)) { - uno::Reference xTransactedObject(xThumbnailStorage, uno::UNO_QUERY_THROW); - xTransactedObject->commit(); - bResult = true; + uno::Reference xTransactedObject(xThumbnailStorage, uno::UNO_QUERY); + if (xTransactedObject) + { + xTransactedObject->commit(); + bResult = true; + } } } } diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx b/sot/source/unoolestorage/xolesimplestorage.cxx index 9336b67bb32f..a3ce980fdbe4 100644 --- a/sot/source/unoolestorage/xolesimplestorage.cxx +++ b/sot/source/unoolestorage/xolesimplestorage.cxx @@ -97,8 +97,9 @@ OLESimpleStorage::OLESimpleStorage( { try { - uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); + uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY ); + if (xSeek) + xSeek->seek( 0 ); } catch( uno::Exception& ) {} diff --git a/svx/source/smarttags/SmartTagMgr.cxx b/svx/source/smarttags/SmartTagMgr.cxx index 084311205109..86322fcc1234 100644 --- a/svx/source/smarttags/SmartTagMgr.cxx +++ b/svx/source/smarttags/SmartTagMgr.cxx @@ -242,7 +242,9 @@ void SmartTagMgr::WriteConfiguration( const bool* pIsLabelTextWithSmartTags, { try { - Reference< util::XChangesBatch >( mxConfigurationSettings, UNO_QUERY_THROW )->commitChanges(); + Reference< util::XChangesBatch > xChanges( mxConfigurationSettings, UNO_QUERY ); + if (xChanges) + xChanges->commitChanges(); } catch ( css::uno::Exception& ) { @@ -446,10 +448,11 @@ void SmartTagMgr::RegisterListener() { Reference xExtensionManager( deployment::ExtensionManager::get( mxContext ) ); - Reference< util::XModifyBroadcaster > xMB ( xExtensionManager, UNO_QUERY_THROW ); - - Reference< util::XModifyListener > xListener( this ); - xMB->addModifyListener( xListener ); + if (xExtensionManager) + { + Reference< util::XModifyListener > xListener( this ); + xExtensionManager->addModifyListener( xListener ); + } } catch ( uno::Exception& ) { @@ -458,9 +461,12 @@ void SmartTagMgr::RegisterListener() // register as listener at configuration try { - Reference xCN( mxConfigurationSettings, UNO_QUERY_THROW ); - Reference< util::XChangesListener > xListener( this ); - xCN->addChangesListener( xListener ); + Reference xCN( mxConfigurationSettings, UNO_QUERY ); + if (xCN) + { + Reference< util::XChangesListener > xListener( this ); + xCN->addChangesListener( xListener ); + } } catch ( uno::Exception& ) { diff --git a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx index 5496f4d4ae9a..a15d81f01be8 100644 --- a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx +++ b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx @@ -101,13 +101,16 @@ void StylesPreviewToolBoxControl::InitializeStyles( if (xCellStyles->hasByName(sStyleName)) { css::uno::Reference xStyle( - xCellStyles->getByName(sStyleName), css::uno::UNO_QUERY_THROW); - OUString sName; - xStyle->getPropertyValue(u"DisplayName"_ustr) >>= sName; - if (!sName.isEmpty()) + xCellStyles->getByName(sStyleName), css::uno::UNO_QUERY); + if (xStyle) { - m_aDefaultStyles.push_back( - std::pair(sStyleName, sName)); + OUString sName; + xStyle->getPropertyValue(u"DisplayName"_ustr) >>= sName; + if (!sName.isEmpty()) + { + m_aDefaultStyles.push_back( + std::pair(sStyleName, sName)); + } } } } diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 95631463bd21..31e0fdc3f109 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -2832,8 +2832,9 @@ SvxLineWindow_Impl::SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::W { try { - Reference< lang::XServiceInfo > xServices(m_xFrame->getController()->getModel(), UNO_QUERY_THROW); - m_bIsWriter = xServices->supportsService(u"com.sun.star.text.TextDocument"_ustr); + Reference< lang::XServiceInfo > xServices(m_xFrame->getController()->getModel(), UNO_QUERY); + if (xServices) + m_bIsWriter = xServices->supportsService(u"com.sun.star.text.TextDocument"_ustr); } catch(const uno::Exception& ) { diff --git a/svx/source/xml/xmleohlp.cxx b/svx/source/xml/xmleohlp.cxx index beb39da14ff8..d931e2a15105 100644 --- a/svx/source/xml/xmleohlp.cxx +++ b/svx/source/xml/xmleohlp.cxx @@ -373,12 +373,16 @@ void SvXMLEmbeddedObjectHelper::ImplReadObject( // TODO/LATER: what to do when other types of objects are based on substream persistence? // This is an ole object - uno::Reference< beans::XPropertySet > xProps( xStm, uno::UNO_QUERY_THROW ); - xProps->setPropertyValue( - u"MediaType"_ustr, - uno::Any( u"application/vnd.sun.star.oleobject"_ustr ) ); + uno::Reference< beans::XPropertySet > xProps( xStm, uno::UNO_QUERY ); + if (xProps) + { + xProps->setPropertyValue( + u"MediaType"_ustr, + uno::Any( u"application/vnd.sun.star.oleobject"_ustr ) ); + - xStm->getOutputStream()->closeOutput(); + xStm->getOutputStream()->closeOutput(); + } } catch ( uno::Exception& ) { diff --git a/svx/source/xml/xmlxtimp.cxx b/svx/source/xml/xmlxtimp.cxx index a6d2b80194b4..a2ce48ddc713 100644 --- a/svx/source/xml/xmlxtimp.cxx +++ b/svx/source/xml/xmlxtimp.cxx @@ -476,8 +476,9 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer, try { - uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); + uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, uno::UNO_QUERY ); + if (xSeek) + xSeek->seek( 0 ); } catch (const uno::Exception&) { -- cgit