diff options
54 files changed, 167 insertions, 408 deletions
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index 15e4719569ba..020f3814ec8c 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -395,8 +395,8 @@ static uno::Reference< vba::XVBACompatibility > getVBACompatibility( const uno:: uno::Reference< vba::XVBACompatibility > xVBACompat; try { - uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW ); - xVBACompat.set( xModelProps->getPropertyValue( "BasicLibraries" ), uno::UNO_QUERY ); + if (auto xModelProps = rxModel.query<beans::XPropertySet>() ) + xVBACompat.set( xModelProps->getPropertyValue( "BasicLibraries" ), uno::UNO_QUERY ); } catch(const uno::Exception& ) { diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx b/comphelper/source/container/embeddedobjectcontainer.cxx index 094597fe6d06..f1281132214e 100644 --- a/comphelper/source/container/embeddedobjectcontainer.cxx +++ b/comphelper/source/container/embeddedobjectcontainer.cxx @@ -1477,9 +1477,9 @@ bool EmbeddedObjectContainer::SetPersistentEntries(const uno::Reference< embed:: // if this method is used as part of SaveCompleted the object must stay unmodified after execution try { - uno::Reference< util::XModifiable > xModif( xObj->getComponent(), uno::UNO_QUERY_THROW ); - if ( xModif->isModified() ) - xModif->setModified( false ); + if (auto xModif = xObj->getComponent().query<util::XModifiable>() ) + if ( xModif->isModified() ) + xModif->setModified( false ); } catch (const uno::Exception&) { diff --git a/comphelper/source/misc/instancelocker.cxx b/comphelper/source/misc/instancelocker.cxx index 84c8054ecbb8..f545ff1480bf 100644 --- a/comphelper/source/misc/instancelocker.cxx +++ b/comphelper/source/misc/instancelocker.cxx @@ -238,13 +238,8 @@ void OLockListener::Dispose() if ( nMode & embed::Actions::PREVENT_TERMINATION ) { - try - { - uno::Reference< frame::XDesktop > xDesktop( xInstance, uno::UNO_QUERY_THROW ); + if (auto xDesktop = xInstance.query<frame::XDesktop>() ) xDesktop->removeTerminateListener( static_cast< frame::XTerminateListener* >( this ) ); - } - catch( uno::Exception& ) - {} } } diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index 9d3dbcd22732..b04c3c9ec58b 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -679,8 +679,8 @@ OUString OStorageHelper::GetODFVersionFromStorage(const uno::Reference<embed::XS OUString aODFVersion; try { - uno::Reference<beans::XPropertySet> xPropSet(xStorage, uno::UNO_QUERY_THROW); - xPropSet->getPropertyValue("Version") >>= aODFVersion; + if (auto xPropSet = xStorage.query<beans::XPropertySet>()) + xPropSet->getPropertyValue("Version") >>= aODFVersion; } catch (uno::Exception&) { diff --git a/embedserv/source/embed/docholder.cxx b/embedserv/source/embed/docholder.cxx index 12300b856517..a70483e0de80 100644 --- a/embedserv/source/embed/docholder.cxx +++ b/embedserv/source/embed/docholder.cxx @@ -603,31 +603,14 @@ void DocumentHolder::FreeOffice() void DocumentHolder::DisconnectFrameDocument( bool bComplete ) { - try - { - uno::Reference< util::XModifyBroadcaster > xModifiable( m_xDocument, uno::UNO_QUERY_THROW ); + if (auto xModifiable = m_xDocument.query<util::XModifyBroadcaster>() ) xModifiable->removeModifyListener( static_cast<util::XModifyListener*>(this) ); - } - catch( const uno::Exception& ) - {} - try - { - uno::Reference< util::XCloseBroadcaster > xBroadcaster( - m_xDocument, uno::UNO_QUERY_THROW ); + if (auto xBroadcaster = m_xDocument.query<util::XCloseBroadcaster>() ) xBroadcaster->removeCloseListener( static_cast<util::XCloseListener*>(this) ); - } - catch( const uno::Exception& ) - {} - try - { - uno::Reference< util::XCloseBroadcaster > xBroadcaster( - m_xFrame, uno::UNO_QUERY_THROW ); + if (auto xBroadcaster = m_xFrame.query<util::XCloseBroadcaster>() ) xBroadcaster->removeCloseListener( static_cast<util::XCloseListener*>(this) ); - } - catch( const uno::Exception& ) - {} if ( bComplete ) { @@ -661,14 +644,8 @@ void DocumentHolder::CloseDocument() void DocumentHolder::CloseFrame() { - try - { - uno::Reference< util::XCloseBroadcaster > xBroadcaster( - m_xFrame, uno::UNO_QUERY_THROW ); + if (auto xBroadcaster = m_xFrame.query<util::XCloseBroadcaster>() ) xBroadcaster->removeCloseListener( static_cast<util::XCloseListener*>(this) ); - } - catch( const uno::Exception& ) - {} uno::Reference<util::XCloseable> xCloseable( m_xFrame,uno::UNO_QUERY); diff --git a/oox/source/drawingml/chart/converterbase.cxx b/oox/source/drawingml/chart/converterbase.cxx index d7130ec9795d..989a5d58541b 100644 --- a/oox/source/drawingml/chart/converterbase.cxx +++ b/oox/source/drawingml/chart/converterbase.cxx @@ -277,15 +277,9 @@ void ConverterRoot::registerTitleLayout( const Reference< XTitle >& rxTitle, void ConverterRoot::convertTitlePositions() { - try - { - Reference< cssc::XChartDocument > xChart1Doc( mxData->mxDoc, UNO_QUERY_THROW ); + if (auto xChart1Doc = mxData->mxDoc.query<cssc::XChartDocument>() ) for (auto & title : mxData->maTitles) title.second.convertTitlePos( *this, xChart1Doc ); - } - catch( Exception& ) - { - } } namespace { diff --git a/oox/source/ole/oleobjecthelper.cxx b/oox/source/ole/oleobjecthelper.cxx index b71f1ade194a..d1f1baf25448 100644 --- a/oox/source/ole/oleobjecthelper.cxx +++ b/oox/source/ole/oleobjecthelper.cxx @@ -74,14 +74,8 @@ OleObjectHelper::OleObjectHelper( OleObjectHelper::~OleObjectHelper() { - try - { - Reference< XComponent > xResolverComp( mxResolver, UNO_QUERY_THROW ); + if (auto xResolverComp = mxResolver.query<XComponent>() ) xResolverComp->dispose(); - } - catch(const Exception& ) - { - } } // TODO: this is probably a sub-optimal approach: ideally the media type diff --git a/oox/source/ole/vbamodule.cxx b/oox/source/ole/vbamodule.cxx index 4bd93cec132c..1a7fa48d15e9 100644 --- a/oox/source/ole/vbamodule.cxx +++ b/oox/source/ole/vbamodule.cxx @@ -323,14 +323,8 @@ void VbaModule::createModule( std::u16string_view rVBASourceCode, aSourceCode.append( "End Sub\n" ); // insert extended module info - try - { - Reference< XVBAModuleInfo > xVBAModuleInfo( rxBasicLib, UNO_QUERY_THROW ); + if (auto xVBAModuleInfo = rxBasicLib.query<XVBAModuleInfo>() ) xVBAModuleInfo->insertModuleInfo( maName, aModuleInfo ); - } - catch (const Exception&) - { - } // insert the module into the passed Basic library try diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx index a52bb103fbb6..2eb6e10683f8 100644 --- a/sc/source/filter/excel/xichart.cxx +++ b/sc/source/filter/excel/xichart.cxx @@ -3988,15 +3988,10 @@ void XclImpChChart::Convert( const Reference<XChartDocument>& xChartDoc, } // chart title - if( mxTitle ) try - { - Reference< XTitled > xTitled( xChartDoc, UNO_QUERY_THROW ); - Reference< XTitle > xTitle( mxTitle->CreateTitle(), UNO_SET_THROW ); - xTitled->setTitleObject( xTitle ); - } - catch( Exception& ) - { - } + if( mxTitle ) + if (auto xTitled = xChartDoc.query<XTitled>() ) + if (auto xTitle = mxTitle->CreateTitle().query<XTitle>() ) + xTitled->setTitleObject( xTitle ); /* Create the diagram object and attach it to the chart document. Currently, one diagram is used to carry all coordinate systems and data series. */ diff --git a/sc/source/filter/ftools/fapihelper.cxx b/sc/source/filter/ftools/fapihelper.cxx index a8cb2f59d102..b81a58e8d64c 100644 --- a/sc/source/filter/ftools/fapihelper.cxx +++ b/sc/source/filter/ftools/fapihelper.cxx @@ -159,8 +159,8 @@ bool ScfPropertySet::HasProperty( const OUString& rPropName ) const bool bHasProp = false; try { - Reference< XPropertyState > xPropState( mxPropSet, UNO_QUERY_THROW ); - bHasProp = xPropState->getPropertyState( rPropName ) == css::beans::PropertyState_DIRECT_VALUE; + if (auto xPropState = mxPropSet.query<XPropertyState>() ) + bHasProp = xPropState->getPropertyState( rPropName ) == css::beans::PropertyState_DIRECT_VALUE; } catch( Exception& ) { diff --git a/sc/source/filter/oox/numberformatsbuffer.cxx b/sc/source/filter/oox/numberformatsbuffer.cxx index 447878000226..8aa9124d882b 100644 --- a/sc/source/filter/oox/numberformatsbuffer.cxx +++ b/sc/source/filter/oox/numberformatsbuffer.cxx @@ -1866,14 +1866,8 @@ private: NumberFormatFinalizer::NumberFormatFinalizer( const WorkbookHelper& rHelper ) : maEnUsLocale( "en", "US", OUString() ) { - try - { - Reference< XNumberFormatsSupplier > xNumFmtsSupp( rHelper.getDocument(), UNO_QUERY_THROW ); + if (auto xNumFmtsSupp = rHelper.getDocument().query<XNumberFormatsSupplier>() ) mxNumFmts = xNumFmtsSupp->getNumberFormats(); - } - catch( Exception& ) - { - } OSL_ENSURE( mxNumFmts.is(), "NumberFormatFinalizer::NumberFormatFinalizer - cannot get number formats" ); } diff --git a/sc/source/filter/oox/pivotcachebuffer.cxx b/sc/source/filter/oox/pivotcachebuffer.cxx index cbbacc8a6123..e796cfe53da0 100644 --- a/sc/source/filter/oox/pivotcachebuffer.cxx +++ b/sc/source/filter/oox/pivotcachebuffer.cxx @@ -646,14 +646,8 @@ OUString PivotCacheField::createDateGroupField( const Reference< XDataPilotField default: OSL_FAIL( "PivotCacheField::convertRangeGrouping - unknown date/time interval" ); } - try - { - Reference< XDataPilotFieldGrouping > xDPGrouping( rxBaseDPField, UNO_QUERY_THROW ); + if (auto xDPGrouping = rxBaseDPField.query<XDataPilotFieldGrouping>() ) xDPGroupField = xDPGrouping->createDateGroup( aGroupInfo ); - } - catch( Exception& ) - { - } } Reference< XNamed > xFieldName( xDPGroupField, UNO_QUERY ); diff --git a/sc/source/filter/oox/pivottablebuffer.cxx b/sc/source/filter/oox/pivottablebuffer.cxx index 637637eb378c..08c0bc8a7dca 100644 --- a/sc/source/filter/oox/pivottablebuffer.cxx +++ b/sc/source/filter/oox/pivottablebuffer.cxx @@ -1409,14 +1409,8 @@ Reference< XDataPilotField > PivotTable::getDataPilotField( sal_Int32 nFieldIdx Reference< XDataPilotField > PivotTable::getDataLayoutField() const { Reference< XDataPilotField > xDPField; - try - { - Reference< XDataPilotDataLayoutFieldSupplier > xDPDataFieldSupp( mxDPDescriptor, UNO_QUERY_THROW ); + if (auto xDPDataFieldSupp = mxDPDescriptor.query<XDataPilotDataLayoutFieldSupplier>() ) xDPField = xDPDataFieldSupp->getDataLayoutField(); - } - catch( Exception& ) - { - } return xDPField; } diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index 495cc0ff7828..34d393c08b3e 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -527,13 +527,8 @@ Reference< XCellRange > WorksheetGlobals::getRow( sal_Int32 nRow ) const Reference< XDrawPage > WorksheetGlobals::getDrawPage() const { Reference< XDrawPage > xDrawPage; - try - { - xDrawPage = Reference< XDrawPageSupplier >( mxSheet, UNO_QUERY_THROW )->getDrawPage(); - } - catch( Exception& ) - { - } + if (auto xSupplier = mxSheet.query<XDrawPageSupplier>()) + xDrawPage = xSupplier->getDrawPage(); return xDrawPage; } diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx index f1eadd91c4b6..a3c19728eb74 100644 --- a/sc/source/filter/xml/xmlwrap.cxx +++ b/sc/source/filter/xml/xmlwrap.cxx @@ -568,9 +568,9 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, ErrCode& rError ) VBA Globals object and does all related initialization. */ if ( xModelSet.is() ) try { - uno::Reference< script::vba::XVBACompatibility > xVBACompat( xModelSet->getPropertyValue( - "BasicLibraries" ), uno::UNO_QUERY_THROW ); - xVBACompat->setVBACompatibilityMode( true ); + if (auto xVBACompat = xModelSet->getPropertyValue( + "BasicLibraries" ).query<script::vba::XVBACompatibility>() ) + xVBACompat->setVBACompatibilityMode( true ); } catch( const uno::Exception& ) { @@ -853,9 +853,8 @@ bool ScXMLImportWrapper::Export(bool bStylesOnly) && aVersion != ODFVER_010_TEXT && aVersion != ODFVER_011_TEXT ) { - const uno::Reference< rdf::XDocumentMetadataAccess > xDMA( - xModel, uno::UNO_QUERY_THROW ); - xDMA->storeMetadataToStorage( xStorage ); + if (auto xDMA = xModel.query<rdf::XDocumentMetadataAccess>() ) + xDMA->storeMetadataToStorage( xStorage ); } } catch ( const beans::UnknownPropertyException &) diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 5902ab697789..8aa6855470df 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -999,14 +999,8 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) TOOLS_WARN_EXCEPTION( "sc", "SfxEventHintId::SaveDoc" ); SC_MOD()->SetInSharedDocSaving( false ); - try - { - uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW ); + if (auto xClose = xModel.query<util::XCloseable>() ) xClose->close( true ); - } - catch ( uno::Exception& ) - { - } } } diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 7e4370b7e6db..7cae44d89c4f 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -1174,14 +1174,8 @@ void ScDocShell::Execute( SfxRequest& rReq ) TOOLS_WARN_EXCEPTION( "sc", "SID_SHARE_DOC" ); SC_MOD()->SetInSharedDocSaving( false ); - try - { - uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW ); + if (auto xClose = xModel.query<util::XCloseable>() ) xClose->close( true ); - } - catch ( uno::Exception& ) - { - } } } } diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index 9cfb3ab31b08..8a4a443b16aa 100644 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -425,26 +425,14 @@ void SAL_CALL ScVbaEventListener::disposing( const lang::EventObject& rEvent ) void ScVbaEventListener::startModelListening() { - try - { - uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW ); + if (auto xChangesNotifier = mxModel.query<util::XChangesNotifier>() ) xChangesNotifier->addChangesListener( this ); - } - catch( uno::Exception& ) - { - } } void ScVbaEventListener::stopModelListening() { - try - { - uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW ); + if (auto xChangesNotifier = mxModel.query<util::XChangesNotifier>() ) xChangesNotifier->removeChangesListener( this ); - } - catch( uno::Exception& ) - { - } } uno::Reference< frame::XController > ScVbaEventListener::getControllerForWindow( vcl::Window* pWindow ) const diff --git a/scripting/source/vbaevents/eventhelper.cxx b/scripting/source/vbaevents/eventhelper.cxx index 420161a22ee1..c139f7d17916 100644 --- a/scripting/source/vbaevents/eventhelper.cxx +++ b/scripting/source/vbaevents/eventhelper.cxx @@ -353,15 +353,8 @@ ScriptEventHelper::~ScriptEventHelper() // dispose control ( and remove any associated event registrations ) if ( m_bDispose ) { - try - { - uno::Reference< lang::XComponent > xComp( m_xControl, uno::UNO_QUERY_THROW ); + if (auto xComp = m_xControl.query<lang::XComponent>() ) xComp->dispose(); - } - // destructor can't throw - catch( uno::Exception& ) - { - } } } diff --git a/sd/source/console/PresenterHelper.cxx b/sd/source/console/PresenterHelper.cxx index 76bec0ecee7d..9bdd580460f8 100644 --- a/sd/source/console/PresenterHelper.cxx +++ b/sd/source/console/PresenterHelper.cxx @@ -36,17 +36,10 @@ Reference<presentation::XSlideShowController> PresenterHelper::GetSlideShowContr { Reference<presentation::XSlideShowController> xSlideShowController; - if( rxController.is() ) try - { - Reference<XPresentationSupplier> xPS ( rxController->getModel(), UNO_QUERY_THROW); - - Reference<XPresentation2> xPresentation(xPS->getPresentation(), UNO_QUERY_THROW); - - xSlideShowController = xPresentation->getController(); - } - catch(RuntimeException&) - { - } + if( rxController.is() ) + if (auto xPS = rxController->getModel().query<XPresentationSupplier>()) + if (auto xPresentation = xPS->getPresentation().query<XPresentation2>()) + xSlideShowController = xPresentation->getController(); return xSlideShowController; } diff --git a/sd/source/console/PresenterScreen.cxx b/sd/source/console/PresenterScreen.cxx index cd6c20d38cc5..dcf0cb93a564 100644 --- a/sd/source/console/PresenterScreen.cxx +++ b/sd/source/console/PresenterScreen.cxx @@ -411,8 +411,8 @@ void PresenterScreen::SwitchMonitors() nNewScreen++; // otherwise we store screens offset by one. // Set the new presentation display - Reference<beans::XPropertySet> xProperties (xPresentation, UNO_QUERY_THROW); - xProperties->setPropertyValue("Display", Any(nNewScreen)); + if (auto xProperties = xPresentation.query<beans::XPropertySet>()) + xProperties->setPropertyValue("Display", Any(nNewScreen)); } catch (const uno::Exception &) { } } diff --git a/sd/source/console/PresenterSlideShowView.cxx b/sd/source/console/PresenterSlideShowView.cxx index 32693f116410..002bc217d659 100644 --- a/sd/source/console/PresenterSlideShowView.cxx +++ b/sd/source/console/PresenterSlideShowView.cxx @@ -799,8 +799,8 @@ Reference<awt::XWindow> PresenterSlideShowView::CreateViewWindow ( xViewWindow.set( xToolkit->createWindow(aWindowDescriptor),UNO_QUERY_THROW); // Make the background transparent. The slide show paints its own background. - Reference<awt::XWindowPeer> xPeer (xViewWindow, UNO_QUERY_THROW); - xPeer->setBackground(0xff000000); + if (auto xPeer = xViewWindow.query<awt::XWindowPeer>()) + xPeer->setBackground(0xff000000); xViewWindow->setVisible(true); } diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx index 2038604861df..d7384ed53b9d 100644 --- a/sd/source/core/stlsheet.cxx +++ b/sd/source/core/stlsheet.cxx @@ -309,9 +309,9 @@ bool SdStyleSheet::IsUsed() const Reference< XStyle > xStyle( rListener, UNO_QUERY ); try { - Reference<XPropertySet> xPropertySet(xStyle, UNO_QUERY_THROW); - if (xPropertySet->getPropertyValue("IsPhysical").get<bool>()) - return true; + if (auto xPropertySet = xStyle.query<XPropertySet>() ) + if (xPropertySet->getPropertyValue("IsPhysical").get<bool>()) + return true; } catch (const Exception&) { diff --git a/sd/source/filter/eppt/epptso.cxx b/sd/source/filter/eppt/epptso.cxx index e794d9600e06..219cf9ebf785 100644 --- a/sd/source/filter/eppt/epptso.cxx +++ b/sd/source/filter/eppt/epptso.cxx @@ -1944,8 +1944,8 @@ void PPTWriter::ImplWritePage( const PHLayout& rLayout, EscherSolverContainer& a try { // try to get the aspect when available - css::uno::Reference< css::beans::XPropertySet > xShapeProps( mXShape, css::uno::UNO_QUERY_THROW ); - xShapeProps->getPropertyValue("Aspect") >>= nAspect; + if (auto xShapeProps = mXShape.query<css::beans::XPropertySet>() ) + xShapeProps->getPropertyValue("Aspect") >>= nAspect; } catch( css::uno::Exception& ) {} @@ -2527,8 +2527,8 @@ void PPTWriter::ImplWritePage( const PHLayout& rLayout, EscherSolverContainer& a try { // try to get the aspect when available - css::uno::Reference< css::beans::XPropertySet > xShapeProps( mXShape, css::uno::UNO_QUERY_THROW ); - xShapeProps->getPropertyValue("Aspect") >>= nAspect; + if (auto xShapeProps = mXShape.query<css::beans::XPropertySet>() ) + xShapeProps->getPropertyValue("Aspect") >>= nAspect; } catch( css::uno::Exception& ) {} diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index 81d6b3c0176b..4f3b6a85048b 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -183,29 +183,15 @@ void AnnotationManagerImpl::init() TOOLS_WARN_EXCEPTION( "sd", "sd::AnnotationManagerImpl::AnnotationManagerImpl()" ); } - try - { - Reference<XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), UNO_QUERY_THROW ); - Reference<XEventListener> xListener( this ); - xModel->addEventListener( xListener ); - } - catch( Exception& ) - { - } + if (auto xModel = mrBase.GetDocShell()->GetModel().query<XEventBroadcaster>() ) + xModel->addEventListener( Reference<XEventListener>( this ) ); } // WeakComponentImplHelper void AnnotationManagerImpl::disposing (std::unique_lock<std::mutex>&) { - try - { - Reference<XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), UNO_QUERY_THROW ); - Reference<XEventListener> xListener( this ); - xModel->removeEventListener( xListener ); - } - catch( Exception& ) - { - } + if (auto xModel = mrBase.GetDocShell()->GetModel().query<XEventBroadcaster>() ) + xModel->removeEventListener( Reference<XEventListener>( this ) ); removeListener(); DisposeTags(); diff --git a/sd/source/ui/slideshow/slideshowviewimpl.cxx b/sd/source/ui/slideshow/slideshowviewimpl.cxx index d6addc3f87fe..4b476812a8d8 100644 --- a/sd/source/ui/slideshow/slideshowviewimpl.cxx +++ b/sd/source/ui/slideshow/slideshowviewimpl.cxx @@ -125,10 +125,9 @@ SlideShowView::SlideShowView( ShowWindow& rOutputWindow, { try { - Reference< beans::XPropertySet > xCanvasProps( getCanvas(), - uno::UNO_QUERY_THROW ); - xCanvasProps->setPropertyValue("UnsafeScrolling", - uno::Any( true ) ); + if (auto xCanvasProps = getCanvas().query<beans::XPropertySet>() ) + xCanvasProps->setPropertyValue("UnsafeScrolling", + uno::Any( true ) ); } catch( uno::Exception& ) { diff --git a/sdext/source/minimizer/impoptimizer.cxx b/sdext/source/minimizer/impoptimizer.cxx index 72be9c666086..8cb61f01cb9c 100644 --- a/sdext/source/minimizer/impoptimizer.cxx +++ b/sdext/source/minimizer/impoptimizer.cxx @@ -73,10 +73,10 @@ static void ImpExtractCustomShow( const Reference< XModel >& rxModel, std::u16st try { PageCollector::CollectNonCustomShowPages( rxModel, rCustomShowName, vNonUsedPageList ); - Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); - Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW ); - for( const auto& rxPage : vNonUsedPageList ) - xDrawPages->remove( rxPage ); + if (auto xDrawPagesSupplier = rxModel.query<XDrawPagesSupplier>() ) + if (auto xDrawPages = xDrawPagesSupplier->getDrawPages().query<XDrawPages>() ) + for( const auto& rxPage : vNonUsedPageList ) + xDrawPages->remove( rxPage ); } catch( Exception& ) { @@ -544,10 +544,12 @@ static void DispatchURL( const Reference< XComponentContext >& xContext, const O aUrl.Complete = sURL; xURLTransformer->parseStrict( aUrl ); Sequence< PropertyValue > aArgs; - Reference< XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY_THROW ); - Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aUrl, OUString(), 0 ); // "_self" - if ( xDispatch.is() ) - xDispatch->dispatch( aUrl, aArgs ); + if (auto xDispatchProvider = xFrame.query<XDispatchProvider>() ) + { + Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aUrl, OUString(), 0 ); // "_self" + if ( xDispatch.is() ) + xDispatch->dispatch( aUrl, aArgs ); + } } catch( Exception& ) { diff --git a/sdext/source/minimizer/optimizationstats.cxx b/sdext/source/minimizer/optimizationstats.cxx index 1deef26ac059..ab958b5cf851 100644 --- a/sdext/source/minimizer/optimizationstats.cxx +++ b/sdext/source/minimizer/optimizationstats.cxx @@ -74,9 +74,9 @@ void OptimizationStats::InitializeStatusValuesFromDocument( const Reference< XMo { try { - Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); - Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW ); - SetStatusValue( TK_Pages, Any( awt::Size( 0, xDrawPages->getCount() ) ) ); + if (auto xDrawPagesSupplier = rxModel.query<XDrawPagesSupplier>() ) + if (auto xDrawPages = xDrawPagesSupplier->getDrawPages().query<XDrawPages>() ) + SetStatusValue( TK_Pages, Any( awt::Size( 0, xDrawPages->getCount() ) ) ); } catch ( Exception& ) { diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 49a8a5b9a08f..b87dc12f0406 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -1109,11 +1109,8 @@ FileDialogHelper_Impl::FileDialogHelper_Impl( if ( mbExport ) { mxFileDlg->setTitle( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) ); - try { - css::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW ); - xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, true ); - } - catch( const Exception & ) { } + if (auto xCtrlAccess = mxFileDlg.query<XFilePickerControlAccess>() ) + xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, true ); } // Save a copy dialog diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index a5fb72251bf1..9178285b7de1 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -1806,8 +1806,8 @@ bool SfxObjectShell_Impl::hasTrustedScriptingSignature( bool bAllowUIToAddAuthor OUString aVersion; try { - uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW ); - xPropSet->getPropertyValue("Version") >>= aVersion; + if (auto xPropSet = rDocShell.GetStorage().query<beans::XPropertySet>() ) + xPropSet->getPropertyValue("Version") >>= aVersion; } catch( uno::Exception& ) { diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 4044bc72fdef..69290515b703 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -1197,8 +1197,8 @@ bool SfxObjectShell::SaveTo_Impl OUString aODFVersion; try { - uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW ); - xPropSet->getPropertyValue("Version") >>= aODFVersion; + if (auto xPropSet = GetStorage().query<beans::XPropertySet>() ) + xPropSet->getPropertyValue("Version") >>= aODFVersion; } catch( uno::Exception& ) {} @@ -1375,9 +1375,9 @@ bool SfxObjectShell::SaveTo_Impl try { - uno::Reference< beans::XPropertySet > xProps( rMedium.GetStorage(), uno::UNO_QUERY_THROW ); - xProps->setPropertyValue("MediaType", - uno::Any( aDataFlavor.MimeType ) ); + if (auto xProps = rMedium.GetStorage().query<beans::XPropertySet>() ) + xProps->setPropertyValue("MediaType", + uno::Any( aDataFlavor.MimeType ) ); } catch( uno::Exception& ) { @@ -1591,8 +1591,8 @@ bool SfxObjectShell::SaveTo_Impl OUString aVersion; try { - uno::Reference < beans::XPropertySet > xPropSet( rMedium.GetStorage(), uno::UNO_QUERY_THROW ); - xPropSet->getPropertyValue("Version") >>= aVersion; + if (auto xPropSet = rMedium.GetStorage().query<beans::XPropertySet>() ) + xPropSet->getPropertyValue("Version") >>= aVersion; } catch( uno::Exception& ) { @@ -1817,14 +1817,16 @@ bool SfxObjectShell::ConnectTmpStorage_Impl( try { // the empty argument means that the storage will create temporary stream itself - uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY_THROW ); - xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() ); + if (auto xOptStorage = xStorage.query<embed::XOptimizedStorage>() ) + { + xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() ); - // the storage is successfully disconnected from the original sources, thus the medium must not dispose it - if ( pMediumArg ) - pMediumArg->CanDisposeStorage_Impl( false ); + // the storage is successfully disconnected from the original sources, thus the medium must not dispose it + if ( pMediumArg ) + pMediumArg->CanDisposeStorage_Impl( false ); - bResult = true; + bResult = true; + } } catch( uno::Exception& ) { @@ -1849,20 +1851,10 @@ bool SfxObjectShell::ConnectTmpStorage_Impl( pImpl->aBasicManager.setStorage( xTmpStorage ); // Get rid of this workaround after issue i113914 is fixed - try - { - uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY_THROW ); + if (auto xBasicLibraries = pImpl->xBasicLibraries.query<script::XStorageBasedLibraryContainer>() ) xBasicLibraries->setRootStorage( xTmpStorage ); - } - catch( uno::Exception& ) - {} - try - { - uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY_THROW ); + if (auto xDialogLibraries = pImpl->xDialogLibraries.query<script::XStorageBasedLibraryContainer>() ) xDialogLibraries->setRootStorage( xTmpStorage ); - } - catch( uno::Exception& ) - {} } } catch( uno::Exception& ) @@ -2013,20 +2005,10 @@ bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed, bool bRegisterRecent ) pImpl->aBasicManager.setStorage( xStorage ); // Get rid of this workaround after issue i113914 is fixed - try - { - uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY_THROW ); + if (auto xBasicLibraries = pImpl->xBasicLibraries.query<script::XStorageBasedLibraryContainer>() ) xBasicLibraries->setRootStorage( xStorage ); - } - catch( uno::Exception& ) - {} - try - { - uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY_THROW ); + if (auto xDialogLibraries = pImpl->xDialogLibraries.query<script::XStorageBasedLibraryContainer>() ) xDialogLibraries->setRootStorage( xStorage ); - } - catch( uno::Exception& ) - {} } else { @@ -3450,9 +3432,9 @@ static bool StoragesOfUnknownMediaTypeAreCopied_Impl( const uno::Reference< embe try { - uno::Reference< embed::XOptimizedStorage > xOptStorage( xSource, uno::UNO_QUERY_THROW ); - bGotMediaType = - ( xOptStorage->getElementPropertyValue( rSubElement, aMediaTypePropName ) >>= aMediaType ); + if (auto xOptStorage = xSource.query<embed::XOptimizedStorage>() ) + bGotMediaType = + ( xOptStorage->getElementPropertyValue( rSubElement, aMediaTypePropName ) >>= aMediaType ); } catch( uno::Exception& ) {} @@ -3593,8 +3575,8 @@ bool SfxObjectShell::CopyStoragesOfUnknownMediaType(const uno::Reference< embed: try { - uno::Reference< embed::XOptimizedStorage > xOptStorage( xSource, uno::UNO_QUERY_THROW ); - bGotMediaType = (xOptStorage->getElementPropertyValue(rSubElement, aMediaTypePropName) + if (auto xOptStorage = xSource.query<embed::XOptimizedStorage>() ) + bGotMediaType = (xOptStorage->getElementPropertyValue(rSubElement, aMediaTypePropName) >>= aMediaType); } catch( uno::Exception& ) diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx b/sot/source/unoolestorage/xolesimplestorage.cxx index 46b82b2b538e..a79e24f48da5 100644 --- a/sot/source/unoolestorage/xolesimplestorage.cxx +++ b/sot/source/unoolestorage/xolesimplestorage.cxx @@ -95,13 +95,8 @@ OLESimpleStorage::OLESimpleStorage( if ( xInputStream.is() ) { - try - { - uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW ); + if (auto xSeek = xInputStream.query<io::XSeekable>() ) xSeek->seek( 0 ); - } - catch( uno::Exception& ) - {} ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, xTempOut ); xTempOut->closeOutput(); diff --git a/svtools/source/misc/bindablecontrolhelper.cxx b/svtools/source/misc/bindablecontrolhelper.cxx index ba5494975695..e127c1a55090 100644 --- a/svtools/source/misc/bindablecontrolhelper.cxx +++ b/svtools/source/misc/bindablecontrolhelper.cxx @@ -45,9 +45,9 @@ static bool lcl_isNamedRange( const OUString& sAddress, const uno::Reference< fr uno::Reference< sheet::XCellRangeReferrer > xReferrer; try { - uno::Reference< beans::XPropertySet > xPropSet( xModel, uno::UNO_QUERY_THROW ); - uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( "NamedRanges" ), uno::UNO_QUERY_THROW ); - xReferrer.set ( xNamed->getByName( sAddress ), uno::UNO_QUERY ); + if (auto xPropSet = xModel.query<beans::XPropertySet>() ) + if (auto xNamed = xPropSet->getPropertyValue( "NamedRanges" ).query<container::XNameAccess>() ) + xReferrer.set ( xNamed->getByName( sAddress ), uno::UNO_QUERY ); } catch( uno::Exception& /*e*/ ) { diff --git a/svx/source/smarttags/SmartTagMgr.cxx b/svx/source/smarttags/SmartTagMgr.cxx index 37b9bc935222..ba3707652342 100644 --- a/svx/source/smarttags/SmartTagMgr.cxx +++ b/svx/source/smarttags/SmartTagMgr.cxx @@ -240,13 +240,8 @@ void SmartTagMgr::WriteConfiguration( const bool* pIsLabelTextWithSmartTags, if ( bCommit ) { - try - { - Reference< util::XChangesBatch >( mxConfigurationSettings, UNO_QUERY_THROW )->commitChanges(); - } - catch ( css::uno::Exception& ) - { - } + if (auto xChangesBatch = mxConfigurationSettings.query<util::XChangesBatch>() ) + xChangesBatch->commitChanges(); } } @@ -448,25 +443,16 @@ void SmartTagMgr::RegisterListener() { Reference<deployment::XExtensionManager> xExtensionManager( deployment::ExtensionManager::get( mxContext ) ); - Reference< util::XModifyBroadcaster > xMB ( xExtensionManager, UNO_QUERY_THROW ); - - Reference< util::XModifyListener > xListener( this ); - xMB->addModifyListener( xListener ); + if (auto xMB = xExtensionManager.query<util::XModifyBroadcaster>() ) + xMB->addModifyListener( Reference< util::XModifyListener >( this ) ); } catch ( uno::Exception& ) { } // register as listener at configuration - try - { - Reference<util::XChangesNotifier> xCN( mxConfigurationSettings, UNO_QUERY_THROW ); - Reference< util::XChangesListener > xListener( this ); - xCN->addChangesListener( xListener ); - } - catch ( uno::Exception& ) - { - } + if (auto xCN = mxConfigurationSettings.query<util::XChangesNotifier>() ) + xCN->addChangesListener( Reference< util::XChangesListener >( this ) ); } typedef std::pair < const OUString, ActionReference > SmartTagMapElement; diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 0d862f8964f8..ea0ede8c0f38 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -2791,14 +2791,8 @@ SvxLineWindow_Impl::SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::W , m_xLineStyleLbWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xLineStyleLb)) , m_bIsWriter(false) { - try - { - Reference< lang::XServiceInfo > xServices(m_xFrame->getController()->getModel(), UNO_QUERY_THROW); + if (auto xServices = m_xFrame->getController()->getModel().query<lang::XServiceInfo>()) m_bIsWriter = xServices->supportsService("com.sun.star.text.TextDocument"); - } - catch(const uno::Exception& ) - { - } m_xLineStyleLb->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) ); diff --git a/svx/source/xml/xmlxtimp.cxx b/svx/source/xml/xmlxtimp.cxx index 19c2a66ce1bb..2da0987c0b61 100644 --- a/svx/source/xml/xmlxtimp.cxx +++ b/svx/source/xml/xmlxtimp.cxx @@ -475,14 +475,8 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer, if (xGraphicHelper.is()) xGraphicStorageHandler = xGraphicHelper.get(); - try - { - uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, uno::UNO_QUERY_THROW ); + if (auto xSeek = aParserInput.aInputStream.query<io::XSeekable>() ) xSeek->seek( 0 ); - } - catch (const uno::Exception&) - { - } rtl::Reference<SvxXMLXTableImport> xImport(new SvxXMLXTableImport(xContext, xTable, xGraphicStorageHandler)); xImport->parseStream( aParserInput ); diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx index de94986797f3..a3cb985d5c85 100644 --- a/sw/source/core/ole/ndole.cxx +++ b/sw/source/core/ole/ndole.cxx @@ -623,10 +623,12 @@ void SwOLENode::BreakFileLink_Impl() try { - uno::Reference< embed::XLinkageSupport > xLinkSupport( maOLEObj.GetOleRef(), uno::UNO_QUERY_THROW ); - xLinkSupport->breakLink( xStorage, maOLEObj.GetCurrentPersistName() ); - DisconnectFileLink_Impl(); - maLinkURL.clear(); + if (auto xLinkSupport = maOLEObj.GetOleRef().query<embed::XLinkageSupport>() ) + { + xLinkSupport->breakLink( xStorage, maOLEObj.GetCurrentPersistName() ); + DisconnectFileLink_Impl(); + maLinkURL.clear(); + } } catch( uno::Exception& ) { diff --git a/sw/source/core/swg/SwXMLTextBlocks.cxx b/sw/source/core/swg/SwXMLTextBlocks.cxx index 3bb108cbf22e..e264548e3c37 100644 --- a/sw/source/core/swg/SwXMLTextBlocks.cxx +++ b/sw/source/core/swg/SwXMLTextBlocks.cxx @@ -295,9 +295,11 @@ ErrCode SwXMLTextBlocks::StartPutBlock( const OUString& rShort, const OUString& { m_xRoot = m_xBlkRoot->openStorageElement( rPackageName, embed::ElementModes::READWRITE ); - uno::Reference< beans::XPropertySet > xRootProps( m_xRoot, uno::UNO_QUERY_THROW ); - OUString aMime( SotExchange::GetFormatMimeType( SotClipboardFormatId::STARWRITER_8 ) ); - xRootProps->setPropertyValue( "MediaType", uno::Any( aMime ) ); + if (auto xRootProps = m_xRoot.query<beans::XPropertySet>() ) + { + OUString aMime( SotExchange::GetFormatMimeType( SotClipboardFormatId::STARWRITER_8 ) ); + xRootProps->setPropertyValue( "MediaType", uno::Any( aMime ) ); + } } catch (const uno::Exception&) { diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx index e5265acc4fec..d14a58badb60 100644 --- a/sw/source/core/unocore/unochart.cxx +++ b/sw/source/core/unocore/unochart.cxx @@ -69,15 +69,8 @@ void SwChartHelper::DoUpdateAllCharts( SwDoc* pDoc ) uno::Reference < embed::XEmbeddedObject > xIP = pONd->GetOLEObj().GetOleRef(); if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) ) { - try - { - uno::Reference< util::XModifiable > xModif( xIP->getComponent(), uno::UNO_QUERY_THROW ); + if (auto xModif = xIP->getComponent().query<util::XModifiable>() ) xModif->setModified( true ); - } - catch ( uno::Exception& ) - { - } - } } aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 ); diff --git a/sw/source/filter/xml/wrtxml.cxx b/sw/source/filter/xml/wrtxml.cxx index a5b0560c1c5a..b302c91c9388 100644 --- a/sw/source/filter/xml/wrtxml.cxx +++ b/sw/source/filter/xml/wrtxml.cxx @@ -307,9 +307,8 @@ ErrCode SwXMLWriter::Write_(const SfxItemSet* pMediumItemSet) && Version != ODFVER_010_TEXT && Version != ODFVER_011_TEXT) { - const uno::Reference<rdf::XDocumentMetadataAccess> xDMA( - xModelComp, uno::UNO_QUERY_THROW); - xDMA->storeMetadataToStorage(m_xStg); + if (auto xDMA = xModelComp.query<rdf::XDocumentMetadataAccess>()) + xDMA->storeMetadataToStorage(m_xStg); } } catch (beans::UnknownPropertyException &) diff --git a/toolkit/source/controls/grid/gridcontrol.cxx b/toolkit/source/controls/grid/gridcontrol.cxx index 0fb9e9695958..bd4c12e692f8 100644 --- a/toolkit/source/controls/grid/gridcontrol.cxx +++ b/toolkit/source/controls/grid/gridcontrol.cxx @@ -167,15 +167,8 @@ namespace { void lcl_dispose_nothrow( const Any& i_component ) { - try - { - const Reference< XComponent > xComponent( i_component, UNO_QUERY_THROW ); + if (auto xComponent = i_component.query<XComponent>() ) xComponent->dispose(); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("toolkit.controls"); - } } } diff --git a/toolkit/source/hatchwindow/documentcloser.cxx b/toolkit/source/hatchwindow/documentcloser.cxx index 6ef68a6a8845..37f72c701f73 100644 --- a/toolkit/source/hatchwindow/documentcloser.cxx +++ b/toolkit/source/hatchwindow/documentcloser.cxx @@ -124,15 +124,8 @@ IMPL_STATIC_LINK( MainThreadFrameCloserRequest, worker, void*, p, void ) // ignore all the errors } - try - { - uno::Reference< util::XCloseable > xCloseable( pMTRequest->m_xFrame, uno::UNO_QUERY_THROW ); + if (auto xCloseable = pMTRequest->m_xFrame.query<util::XCloseable>() ) xCloseable->close( true ); - } - catch( uno::Exception& ) - { - // ignore all the errors - } } delete pMTRequest; diff --git a/unotools/source/config/confignode.cxx b/unotools/source/config/confignode.cxx index 93b89532072d..cf5dcb0e64ae 100644 --- a/unotools/source/config/confignode.cxx +++ b/unotools/source/config/confignode.cxx @@ -146,15 +146,8 @@ namespace utl OUString OConfigurationNode::getLocalName() const { OUString sLocalName; - try - { - Reference< XNamed > xNamed( m_xDirectAccess, UNO_QUERY_THROW ); + if (auto xNamed = m_xDirectAccess.query<XNamed>() ) sLocalName = xNamed->getName(); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("unotools"); - } return sLocalName; } diff --git a/unotools/source/config/lingucfg.cxx b/unotools/source/config/lingucfg.cxx index 0b39db9172ef..6c3f625dd76d 100644 --- a/unotools/source/config/lingucfg.cxx +++ b/unotools/source/config/lingucfg.cxx @@ -1016,9 +1016,11 @@ uno::Sequence< OUString > SvtLinguConfig::GetDisabledDictionaries() const uno::Sequence< OUString > aResult; try { - uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW ); - xNA.set( xNA->getByName("ServiceManager"), uno::UNO_QUERY_THROW ); - xNA->getByName( "DisabledDictionaries" ) >>= aResult; + if (auto xNA = GetMainUpdateAccess().query<container::XNameAccess>() ) + { + xNA.set( xNA->getByName("ServiceManager"), uno::UNO_QUERY_THROW ); + xNA->getByName( "DisabledDictionaries" ) >>= aResult; + } } catch (uno::Exception &) { diff --git a/unotools/source/config/useroptions.cxx b/unotools/source/config/useroptions.cxx index 1e181e8813d6..4cfc3f125358 100644 --- a/unotools/source/config/useroptions.cxx +++ b/unotools/source/config/useroptions.cxx @@ -117,14 +117,8 @@ void SvtUserOptions::ChangeListener::changesOccurred (util::ChangesEvent const& void SvtUserOptions::ChangeListener::disposing (lang::EventObject const& rSource) { - try - { - uno::Reference<util::XChangesNotifier> xChgNot(rSource.Source, uno::UNO_QUERY_THROW); + if (auto xChgNot = rSource.Source.query<util::XChangesNotifier>()) xChgNot->removeChangesListener(this); - } - catch (uno::Exception&) - { - } } SvtUserOptions::Impl::Impl() : diff --git a/vbahelper/source/msforms/vbauserform.cxx b/vbahelper/source/msforms/vbauserform.cxx index 66aa6eff7198..50ba5a39ad90 100644 --- a/vbahelper/source/msforms/vbauserform.cxx +++ b/vbahelper/source/msforms/vbauserform.cxx @@ -88,16 +88,12 @@ ScVbaUserForm::Show( ) if ( !mbDispose ) return; - try + if (auto xComp = m_xDialog.query<lang::XComponent>() ) { - uno::Reference< lang::XComponent > xComp( m_xDialog, uno::UNO_QUERY_THROW ); m_xDialog = nullptr; xComp->dispose(); mbDispose = false; } - catch( uno::Exception& ) - { - } } OUString SAL_CALL diff --git a/vbahelper/source/vbahelper/vbacolorformat.cxx b/vbahelper/source/vbahelper/vbacolorformat.cxx index 56180a98fb6a..8f0ad989c197 100644 --- a/vbahelper/source/vbahelper/vbacolorformat.cxx +++ b/vbahelper/source/vbahelper/vbacolorformat.cxx @@ -43,14 +43,10 @@ ScVbaColorFormat::ScVbaColorFormat( const uno::Reference< XHelperInterface >& xP { m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW ); m_nFillFormatBackColor = 0; - try - { - uno::Reference< ov::msforms::XFillFormat > xFillFormat( xInternalParent, uno::UNO_QUERY_THROW ); + if (auto xFillFormat = xInternalParent.query<ov::msforms::XFillFormat>() ) m_pFillFormat = static_cast<ScVbaFillFormat*>( xFillFormat.get() ); - }catch ( uno::RuntimeException& ) - { + else m_pFillFormat = nullptr; - } } // Attribute diff --git a/vbahelper/source/vbahelper/vbadocumentbase.cxx b/vbahelper/source/vbahelper/vbadocumentbase.cxx index 0a2cc5b8705b..5231a1497135 100644 --- a/vbahelper/source/vbahelper/vbadocumentbase.cxx +++ b/vbahelper/source/vbahelper/vbadocumentbase.cxx @@ -192,16 +192,11 @@ VbaDocumentBase::Close( const uno::Any &rSaveArg, const uno::Any &rFileArg, if (bCloseable) return; - try { - // If close is not supported by this model - try to dispose it. - // But if the model disagree with a reset request for the modify state - // we shouldn't do so. Otherwise some strange things can happen. - uno::Reference< lang::XComponent > xDisposable ( xModel, uno::UNO_QUERY_THROW ); + // If close is not supported by this model - try to dispose it. + // But if the model disagree with a reset request for the modify state + // we shouldn't do so. Otherwise some strange things can happen. + if (auto xDisposable = xModel.query<lang::XComponent>() ) xDisposable->dispose(); - } - catch(const uno::Exception&) - { - } } void diff --git a/vbahelper/source/vbahelper/vbadocumentsbase.cxx b/vbahelper/source/vbahelper/vbadocumentsbase.cxx index 6db5b5a4cac0..d35b4e3f83ed 100644 --- a/vbahelper/source/vbahelper/vbadocumentsbase.cxx +++ b/vbahelper/source/vbahelper/vbadocumentsbase.cxx @@ -198,24 +198,21 @@ namespace { void lclSetupComponent( const uno::Reference< lang::XComponent >& rxComponent, bool bScreenUpdating, bool bInteractive ) { - if( !bScreenUpdating ) try - { - uno::Reference< frame::XModel >( rxComponent, uno::UNO_QUERY_THROW )->lockControllers(); - } - catch( uno::Exception& ) - { - } + auto xModel = rxComponent.query<frame::XModel>(); + if( !bScreenUpdating && xModel ) + xModel->lockControllers(); - if( !bInteractive ) try - { - uno::Reference< frame::XModel > xModel( rxComponent, uno::UNO_QUERY_THROW ); - uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); - uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW ); - uno::Reference< awt::XWindow >( xFrame->getContainerWindow(), uno::UNO_SET_THROW )->setEnable( false ); - } - catch( uno::Exception& ) - { - } + if( !bInteractive ) + try + { + if (auto xController = xModel->getCurrentController().query<frame::XController>() ) + if (auto xFrame = xController->getFrame().query<frame::XFrame>() ) + if (auto xWindow = xFrame->getContainerWindow().query<awt::XWindow>() ) + xWindow->setEnable( false ); + } + catch( uno::Exception& ) + { + } } } // namespace diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index a9522e53db2c..d9faf0c206a4 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -4498,16 +4498,12 @@ void DomainMapper_Impl::PopShapeContext() // or anchored to a discarded header or footer if ( m_aAnchoredStack.top().bToRemove || m_bDiscardHeaderFooter ) { - try + if (auto xDrawPageSupplier = m_xTextDocument.query<drawing::XDrawPageSupplier>()) { - uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(m_xTextDocument, uno::UNO_QUERY_THROW); uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); if ( xDrawPage.is() ) xDrawPage->remove( xShape ); } - catch( const uno::Exception& ) - { - } } // Relative width calculations deferred until section's margins are defined. diff --git a/writerfilter/source/dmapper/ModelEventListener.cxx b/writerfilter/source/dmapper/ModelEventListener.cxx index 4df26105a37c..6b5ff87317a2 100644 --- a/writerfilter/source/dmapper/ModelEventListener.cxx +++ b/writerfilter/source/dmapper/ModelEventListener.cxx @@ -102,14 +102,8 @@ void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) void ModelEventListener::disposing( const lang::EventObject& rEvent ) { - try - { - uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY_THROW )->removeEventListener( - uno::Reference<document::XEventListener>(this)); - } - catch( const uno::Exception& ) - { - } + if (auto xEventBroadcaster = rEvent.Source.query<document::XEventBroadcaster>()) + xEventBroadcaster->removeEventListener(uno::Reference<document::XEventListener>(this)); } } //namespace writerfilter::dmapper diff --git a/writerfilter/source/dmapper/OLEHandler.cxx b/writerfilter/source/dmapper/OLEHandler.cxx index e0671c8a21b6..bfa6a7d37bdf 100644 --- a/writerfilter/source/dmapper/OLEHandler.cxx +++ b/writerfilter/source/dmapper/OLEHandler.cxx @@ -315,8 +315,8 @@ OUString OLEHandler::copyOLEOStream( sRet = aPersistName.copy( strlen("vnd.sun.star.EmbeddedObject:") ); } - uno::Reference< lang::XComponent > xComp( xEmbeddedResolver, uno::UNO_QUERY_THROW ); - xComp->dispose(); + if (auto xComp = xEmbeddedResolver.query<lang::XComponent>() ) + xComp->dispose(); m_aURL = aURL; } catch( const uno::Exception& ) diff --git a/xmloff/source/chart/SchXMLTableContext.cxx b/xmloff/source/chart/SchXMLTableContext.cxx index b12f5886e69b..b13394b54fdb 100644 --- a/xmloff/source/chart/SchXMLTableContext.cxx +++ b/xmloff/source/chart/SchXMLTableContext.cxx @@ -765,9 +765,11 @@ void SchXMLTableHelper::applyTableToInternalDataProvider( { try { - Reference< beans::XPropertySet > xProps( xChartDoc, uno::UNO_QUERY_THROW ); - xProps->setPropertyValue( "DisableDataTableDialog", uno::Any( true ) ); - xProps->setPropertyValue( "DisableComplexChartTypes", uno::Any( true ) ); + if (auto xProps = xChartDoc.query<beans::XPropertySet>() ) + { + xProps->setPropertyValue( "DisableDataTableDialog", uno::Any( true ) ); + xProps->setPropertyValue( "DisableComplexChartTypes", uno::Any( true ) ); + } } catch ( uno::Exception& ) { diff --git a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx index 980dd8e0572d..f55edf062e74 100644 --- a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx +++ b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx @@ -122,14 +122,8 @@ void XMLEmbeddedObjectImportContext::SetComponent( Reference< XComponent > const SvXMLImport *pFastHandler = dynamic_cast<SvXMLImport*>(xFilter.get()); mxFastHandler = pFastHandler; - try - { - Reference < XModifiable2 > xModifiable2( rComp, UNO_QUERY_THROW ); + if (auto xModifiable2 = rComp.query<XModifiable2>() ) xModifiable2->disableSetModified(); - } - catch( Exception& ) - { - } Reference < XImporter > xImporter( mxFastHandler, UNO_QUERY ); xImporter->setTargetDocument( rComp ); @@ -242,15 +236,11 @@ void XMLEmbeddedObjectImportContext::endFastElement(sal_Int32 nElement) mxFastHandler->endFastElement( nElement ); mxFastHandler->endDocument(); - try + if (auto xModifiable2 = xComp.query<XModifiable2>() ) { - Reference < XModifiable2 > xModifiable2( xComp, UNO_QUERY_THROW ); xModifiable2->enableSetModified(); xModifiable2->setModified( true ); // trigger new replacement image generation } - catch( Exception& ) - { - } } void XMLEmbeddedObjectImportContext::characters( const OUString& rChars ) |