basic/source/classes/sbxmod.cxx                         |    4 
 comphelper/source/container/embeddedobjectcontainer.cxx |    6 -
 comphelper/source/misc/instancelocker.cxx               |    7 +
 comphelper/source/misc/storagehelper.cxx                |    4 
 embedserv/source/embed/docholder.cxx                    |   31 ++++++-
 oox/source/drawingml/chart/converterbase.cxx            |    8 +
 oox/source/ole/oleobjecthelper.cxx                      |    8 +
 oox/source/ole/vbamodule.cxx                            |    8 +
 sc/source/filter/excel/xichart.cxx                      |   13 ++-
 sc/source/filter/ftools/fapihelper.cxx                  |    4 
 sc/source/filter/oox/numberformatsbuffer.cxx            |    8 +
 sc/source/filter/oox/pivotcachebuffer.cxx               |    8 +
 sc/source/filter/oox/pivottablebuffer.cxx               |    8 +
 sc/source/filter/oox/worksheethelper.cxx                |    9 +-
 sc/source/filter/xml/xmlwrap.cxx                        |   11 +-
 sc/source/ui/docshell/docsh.cxx                         |    8 +
 sc/source/ui/docshell/docsh4.cxx                        |    8 +
 sc/source/ui/vba/vbaeventshelper.cxx                    |   16 +++
 scripting/source/vbaevents/eventhelper.cxx              |    9 +-
 sd/source/console/PresenterHelper.cxx                   |   15 ++-
 sd/source/console/PresenterScreen.cxx                   |    4 
 sd/source/console/PresenterSlideShowView.cxx            |    4 
 sd/source/core/stlsheet.cxx                             |    6 -
 sd/source/filter/eppt/epptso.cxx                        |    8 -
 sd/source/ui/annotations/annotationmanager.cxx          |   22 ++++-
 sd/source/ui/slideshow/slideshowviewimpl.cxx            |    7 -
 sdext/source/minimizer/impoptimizer.cxx                 |   18 +---
 sdext/source/minimizer/optimizationstats.cxx            |    6 -
 sfx2/source/dialog/filedlghelper.cxx                    |    7 +
 sfx2/source/doc/objmisc.cxx                             |    4 
 sfx2/source/doc/objstor.cxx                             |   66 ++++++++++------
 sot/source/unoolestorage/xolesimplestorage.cxx          |    7 +
 svtools/source/misc/bindablecontrolhelper.cxx           |    6 -
 svx/source/smarttags/SmartTagMgr.cxx                    |   26 ++++--
 svx/source/tbxctrls/tbcontrl.cxx                        |    8 +
 svx/source/xml/xmlxtimp.cxx                             |    8 +
 sw/source/core/ole/ndole.cxx                            |   10 --
 sw/source/core/swg/SwXMLTextBlocks.cxx                  |    8 -
 sw/source/core/unocore/unochart.cxx                     |    9 +-
 sw/source/filter/xml/wrtxml.cxx                         |    5 -
 toolkit/source/controls/grid/gridcontrol.cxx            |    9 +-
 toolkit/source/hatchwindow/documentcloser.cxx           |    9 +-
 unotools/source/config/confignode.cxx                   |    9 +-
 unotools/source/config/lingucfg.cxx                     |    8 -
 unotools/source/config/useroptions.cxx                  |    8 +
 vbahelper/source/msforms/vbauserform.cxx                |    6 +
 vbahelper/source/vbahelper/vbacolorformat.cxx           |    8 +
 vbahelper/source/vbahelper/vbadocumentbase.cxx          |   13 ++-
 vbahelper/source/vbahelper/vbadocumentsbase.cxx         |   31 ++++---
 writerfilter/source/dmapper/DomainMapper_Impl.cxx       |    6 +
 writerfilter/source/dmapper/ModelEventListener.cxx      |   10 +-
 writerfilter/source/dmapper/OLEHandler.cxx              |    4 
 xmloff/source/chart/SchXMLTableContext.cxx              |    8 -
 xmloff/source/core/XMLEmbeddedObjectImportContext.cxx   |   14 ++-
 54 files changed, 408 insertions(+), 167 deletions(-)

New commits:
commit 87db52ab1e9c39ad8319aaf9c0c59d4435b6ffb5
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Aug 25 11:30:42 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Aug 25 14:15:56 2023 +0200

    Revert "use more Reference::query instead of UNO_QUERY_THROW"
    
    This reverts commit 7fc6063914432d58d86cfcbd728d967e7c86ebfd.
    
    sberg noticed that there is a difference now:
    
    there's a subtle difference now, in that if  y  was null originally, it 
would have thrown a (caught) exception, whereas now it will crash in the  
y.query<X>()  call.
    
    Change-Id: Idbb5a08d635d15b5ca63f4822eddf05fb0a5afa0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156002
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index 020f3814ec8c..15e4719569ba 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
     {
-        if (auto xModelProps = rxModel.query<beans::XPropertySet>() )
-            xVBACompat.set( xModelProps->getPropertyValue( "BasicLibraries" ), 
uno::UNO_QUERY );
+        uno::Reference< beans::XPropertySet > xModelProps( rxModel, 
uno::UNO_QUERY_THROW );
+        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 f1281132214e..094597fe6d06 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
                 {
-                    if (auto xModif = 
xObj->getComponent().query<util::XModifiable>() )
-                        if ( xModif->isModified() )
-                            xModif->setModified( false );
+                    uno::Reference< util::XModifiable > xModif( 
xObj->getComponent(), uno::UNO_QUERY_THROW );
+                    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 f545ff1480bf..84c8054ecbb8 100644
--- a/comphelper/source/misc/instancelocker.cxx
+++ b/comphelper/source/misc/instancelocker.cxx
@@ -238,8 +238,13 @@ void OLockListener::Dispose()
 
     if ( nMode & embed::Actions::PREVENT_TERMINATION )
     {
-        if (auto xDesktop = xInstance.query<frame::XDesktop>() )
+        try
+        {
+            uno::Reference< frame::XDesktop > xDesktop( xInstance, 
uno::UNO_QUERY_THROW );
             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 b04c3c9ec58b..9d3dbcd22732 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
     {
-        if (auto xPropSet = xStorage.query<beans::XPropertySet>())
-            xPropSet->getPropertyValue("Version") >>= aODFVersion;
+        uno::Reference<beans::XPropertySet> xPropSet(xStorage, 
uno::UNO_QUERY_THROW);
+        xPropSet->getPropertyValue("Version") >>= aODFVersion;
     }
     catch (uno::Exception&)
     {
diff --git a/embedserv/source/embed/docholder.cxx 
b/embedserv/source/embed/docholder.cxx
index a70483e0de80..12300b856517 100644
--- a/embedserv/source/embed/docholder.cxx
+++ b/embedserv/source/embed/docholder.cxx
@@ -603,14 +603,31 @@ void DocumentHolder::FreeOffice()
 
 void DocumentHolder::DisconnectFrameDocument( bool bComplete )
 {
-    if (auto xModifiable = m_xDocument.query<util::XModifyBroadcaster>() )
+    try
+    {
+        uno::Reference< util::XModifyBroadcaster > xModifiable( m_xDocument, 
uno::UNO_QUERY_THROW );
         xModifiable->removeModifyListener( 
static_cast<util::XModifyListener*>(this) );
+    }
+    catch( const uno::Exception& )
+    {}
 
-    if (auto xBroadcaster = m_xDocument.query<util::XCloseBroadcaster>() )
+    try
+    {
+        uno::Reference< util::XCloseBroadcaster > xBroadcaster(
+            m_xDocument, uno::UNO_QUERY_THROW );
         xBroadcaster->removeCloseListener( 
static_cast<util::XCloseListener*>(this) );
+    }
+    catch( const uno::Exception& )
+    {}
 
-    if (auto xBroadcaster = m_xFrame.query<util::XCloseBroadcaster>() )
+    try
+    {
+        uno::Reference< util::XCloseBroadcaster > xBroadcaster(
+            m_xFrame, uno::UNO_QUERY_THROW );
         xBroadcaster->removeCloseListener( 
static_cast<util::XCloseListener*>(this) );
+    }
+    catch( const uno::Exception& )
+    {}
 
     if ( bComplete )
     {
@@ -644,8 +661,14 @@ void DocumentHolder::CloseDocument()
 
 void DocumentHolder::CloseFrame()
 {
-    if (auto xBroadcaster = m_xFrame.query<util::XCloseBroadcaster>() )
+    try
+    {
+        uno::Reference< util::XCloseBroadcaster > xBroadcaster(
+            m_xFrame, uno::UNO_QUERY_THROW );
         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 989a5d58541b..d7130ec9795d 100644
--- a/oox/source/drawingml/chart/converterbase.cxx
+++ b/oox/source/drawingml/chart/converterbase.cxx
@@ -277,9 +277,15 @@ void ConverterRoot::registerTitleLayout( const Reference< 
XTitle >& rxTitle,
 
 void ConverterRoot::convertTitlePositions()
 {
-    if (auto xChart1Doc = mxData->mxDoc.query<cssc::XChartDocument>() )
+    try
+    {
+        Reference< cssc::XChartDocument > xChart1Doc( mxData->mxDoc, 
UNO_QUERY_THROW );
         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 d1f1baf25448..b71f1ade194a 100644
--- a/oox/source/ole/oleobjecthelper.cxx
+++ b/oox/source/ole/oleobjecthelper.cxx
@@ -74,8 +74,14 @@ OleObjectHelper::OleObjectHelper(
 
 OleObjectHelper::~OleObjectHelper()
 {
-    if (auto xResolverComp = mxResolver.query<XComponent>() )
+    try
+    {
+        Reference< XComponent > xResolverComp( mxResolver, UNO_QUERY_THROW );
         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 1a7fa48d15e9..4bd93cec132c 100644
--- a/oox/source/ole/vbamodule.cxx
+++ b/oox/source/ole/vbamodule.cxx
@@ -323,8 +323,14 @@ void VbaModule::createModule( std::u16string_view 
rVBASourceCode,
         aSourceCode.append( "End Sub\n" );
 
     // insert extended module info
-    if (auto xVBAModuleInfo = rxBasicLib.query<XVBAModuleInfo>() )
+    try
+    {
+        Reference< XVBAModuleInfo > xVBAModuleInfo( rxBasicLib, 
UNO_QUERY_THROW );
         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 2eb6e10683f8..a52bb103fbb6 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -3988,10 +3988,15 @@ void XclImpChChart::Convert( const 
Reference<XChartDocument>& xChartDoc,
     }
 
     // chart title
-    if( mxTitle )
-        if (auto xTitled = xChartDoc.query<XTitled>() )
-            if (auto xTitle = mxTitle->CreateTitle().query<XTitle>() )
-                xTitled->setTitleObject( xTitle );
+    if( mxTitle ) try
+    {
+        Reference< XTitled > xTitled( xChartDoc, UNO_QUERY_THROW );
+        Reference< XTitle > xTitle( mxTitle->CreateTitle(), UNO_SET_THROW );
+        xTitled->setTitleObject( xTitle );
+    }
+    catch( Exception& )
+    {
+    }
 
     /*  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 b81a58e8d64c..a8cb2f59d102 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
     {
-        if (auto xPropState = mxPropSet.query<XPropertyState>() )
-            bHasProp = xPropState->getPropertyState( rPropName ) == 
css::beans::PropertyState_DIRECT_VALUE;
+        Reference< XPropertyState > xPropState( mxPropSet, UNO_QUERY_THROW );
+        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 8aa9124d882b..447878000226 100644
--- a/sc/source/filter/oox/numberformatsbuffer.cxx
+++ b/sc/source/filter/oox/numberformatsbuffer.cxx
@@ -1866,8 +1866,14 @@ private:
 NumberFormatFinalizer::NumberFormatFinalizer( const WorkbookHelper& rHelper ) :
     maEnUsLocale( "en", "US", OUString() )
 {
-    if (auto xNumFmtsSupp = 
rHelper.getDocument().query<XNumberFormatsSupplier>() )
+    try
+    {
+        Reference< XNumberFormatsSupplier > xNumFmtsSupp( 
rHelper.getDocument(), UNO_QUERY_THROW );
         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 3655ffc40391..d8cf350bf9a5 100644
--- a/sc/source/filter/oox/pivotcachebuffer.cxx
+++ b/sc/source/filter/oox/pivotcachebuffer.cxx
@@ -646,8 +646,14 @@ OUString PivotCacheField::createDateGroupField( const 
Reference< XDataPilotField
             default:    OSL_FAIL( "PivotCacheField::convertRangeGrouping - 
unknown date/time interval" );
         }
 
-        if (auto xDPGrouping = rxBaseDPField.query<XDataPilotFieldGrouping>() )
+        try
+        {
+            Reference< XDataPilotFieldGrouping > xDPGrouping( rxBaseDPField, 
UNO_QUERY_THROW );
             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 08c0bc8a7dca..637637eb378c 100644
--- a/sc/source/filter/oox/pivottablebuffer.cxx
+++ b/sc/source/filter/oox/pivottablebuffer.cxx
@@ -1409,8 +1409,14 @@ Reference< XDataPilotField > 
PivotTable::getDataPilotField( sal_Int32 nFieldIdx
 Reference< XDataPilotField > PivotTable::getDataLayoutField() const
 {
     Reference< XDataPilotField > xDPField;
-    if (auto xDPDataFieldSupp = 
mxDPDescriptor.query<XDataPilotDataLayoutFieldSupplier>() )
+    try
+    {
+        Reference< XDataPilotDataLayoutFieldSupplier > xDPDataFieldSupp( 
mxDPDescriptor, UNO_QUERY_THROW );
         xDPField = xDPDataFieldSupp->getDataLayoutField();
+    }
+    catch( Exception& )
+    {
+    }
     return xDPField;
 }
 
diff --git a/sc/source/filter/oox/worksheethelper.cxx 
b/sc/source/filter/oox/worksheethelper.cxx
index 34d393c08b3e..495cc0ff7828 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -527,8 +527,13 @@ Reference< XCellRange > WorksheetGlobals::getRow( 
sal_Int32 nRow ) const
 Reference< XDrawPage > WorksheetGlobals::getDrawPage() const
 {
     Reference< XDrawPage > xDrawPage;
-    if (auto xSupplier = mxSheet.query<XDrawPageSupplier>())
-        xDrawPage = xSupplier->getDrawPage();
+    try
+    {
+        xDrawPage = Reference< XDrawPageSupplier >( mxSheet, UNO_QUERY_THROW 
)->getDrawPage();
+    }
+    catch( Exception& )
+    {
+    }
     return xDrawPage;
 }
 
diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx
index a3c19728eb74..f1eadd91c4b6 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
             {
-                if (auto xVBACompat = xModelSet->getPropertyValue(
-                    "BasicLibraries" ).query<script::vba::XVBACompatibility>() 
)
-                    xVBACompat->setVBACompatibilityMode( true );
+                uno::Reference< script::vba::XVBACompatibility > xVBACompat( 
xModelSet->getPropertyValue(
+                    "BasicLibraries" ), uno::UNO_QUERY_THROW );
+                xVBACompat->setVBACompatibilityMode( true );
             }
             catch( const uno::Exception& )
             {
@@ -853,8 +853,9 @@ bool ScXMLImportWrapper::Export(bool bStylesOnly)
                     && aVersion != ODFVER_010_TEXT
                     && aVersion != ODFVER_011_TEXT )
                 {
-                    if (auto xDMA = 
xModel.query<rdf::XDocumentMetadataAccess>() )
-                        xDMA->storeMetadataToStorage( xStorage );
+                    const uno::Reference< rdf::XDocumentMetadataAccess > xDMA(
+                        xModel, uno::UNO_QUERY_THROW );
+                    xDMA->storeMetadataToStorage( xStorage );
                 }
             }
             catch ( const beans::UnknownPropertyException &)
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 8aa6855470df..5902ab697789 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -999,8 +999,14 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
                                 TOOLS_WARN_EXCEPTION( "sc", 
"SfxEventHintId::SaveDoc" );
                                 SC_MOD()->SetInSharedDocSaving( false );
 
-                                if (auto xClose = 
xModel.query<util::XCloseable>() )
+                                try
+                                {
+                                    uno::Reference< util::XCloseable > xClose( 
xModel, uno::UNO_QUERY_THROW );
                                     xClose->close( true );
+                                }
+                                catch ( uno::Exception& )
+                                {
+                                }
                             }
                         }
 
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 7cae44d89c4f..7e4370b7e6db 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -1174,8 +1174,14 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                 TOOLS_WARN_EXCEPTION( "sc", "SID_SHARE_DOC" );
                                 SC_MOD()->SetInSharedDocSaving( false );
 
-                                if (auto xClose = 
xModel.query<util::XCloseable>() )
+                                try
+                                {
+                                    uno::Reference< util::XCloseable > xClose( 
xModel, uno::UNO_QUERY_THROW );
                                     xClose->close( true );
+                                }
+                                catch ( uno::Exception& )
+                                {
+                                }
                             }
                         }
                     }
diff --git a/sc/source/ui/vba/vbaeventshelper.cxx 
b/sc/source/ui/vba/vbaeventshelper.cxx
index 8a4a443b16aa..9cfb3ab31b08 100644
--- a/sc/source/ui/vba/vbaeventshelper.cxx
+++ b/sc/source/ui/vba/vbaeventshelper.cxx
@@ -425,14 +425,26 @@ void SAL_CALL ScVbaEventListener::disposing( const 
lang::EventObject& rEvent )
 
 void ScVbaEventListener::startModelListening()
 {
-    if (auto xChangesNotifier = mxModel.query<util::XChangesNotifier>() )
+    try
+    {
+        uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, 
uno::UNO_QUERY_THROW );
         xChangesNotifier->addChangesListener( this );
+    }
+    catch( uno::Exception& )
+    {
+    }
 }
 
 void ScVbaEventListener::stopModelListening()
 {
-    if (auto xChangesNotifier = mxModel.query<util::XChangesNotifier>() )
+    try
+    {
+        uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, 
uno::UNO_QUERY_THROW );
         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 c139f7d17916..420161a22ee1 100644
--- a/scripting/source/vbaevents/eventhelper.cxx
+++ b/scripting/source/vbaevents/eventhelper.cxx
@@ -353,8 +353,15 @@ ScriptEventHelper::~ScriptEventHelper()
     // dispose control ( and remove any associated event registrations )
     if ( m_bDispose )
     {
-        if (auto xComp = m_xControl.query<lang::XComponent>() )
+        try
+        {
+            uno::Reference< lang::XComponent > xComp( m_xControl, 
uno::UNO_QUERY_THROW );
             xComp->dispose();
+        }
+        // destructor can't throw
+        catch( uno::Exception& )
+        {
+        }
     }
 }
 
diff --git a/sd/source/console/PresenterHelper.cxx 
b/sd/source/console/PresenterHelper.cxx
index 9bdd580460f8..76bec0ecee7d 100644
--- a/sd/source/console/PresenterHelper.cxx
+++ b/sd/source/console/PresenterHelper.cxx
@@ -36,10 +36,17 @@ Reference<presentation::XSlideShowController> 
PresenterHelper::GetSlideShowContr
 {
     Reference<presentation::XSlideShowController> xSlideShowController;
 
-    if( rxController.is() )
-        if (auto xPS = rxController->getModel().query<XPresentationSupplier>())
-            if (auto xPresentation = 
xPS->getPresentation().query<XPresentation2>())
-                xSlideShowController = xPresentation->getController();
+    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&)
+    {
+    }
 
     return xSlideShowController;
 }
diff --git a/sd/source/console/PresenterScreen.cxx 
b/sd/source/console/PresenterScreen.cxx
index dcf0cb93a564..cd6c20d38cc5 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
-        if (auto xProperties = xPresentation.query<beans::XPropertySet>())
-            xProperties->setPropertyValue("Display", Any(nNewScreen));
+        Reference<beans::XPropertySet> xProperties (xPresentation, 
UNO_QUERY_THROW);
+        xProperties->setPropertyValue("Display", Any(nNewScreen));
     } catch (const uno::Exception &) {
     }
 }
diff --git a/sd/source/console/PresenterSlideShowView.cxx 
b/sd/source/console/PresenterSlideShowView.cxx
index 002bc217d659..32693f116410 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.
-        if (auto xPeer = xViewWindow.query<awt::XWindowPeer>())
-            xPeer->setBackground(0xff000000);
+        Reference<awt::XWindowPeer> xPeer (xViewWindow, UNO_QUERY_THROW);
+        xPeer->setBackground(0xff000000);
 
         xViewWindow->setVisible(true);
     }
diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx
index d7384ed53b9d..2038604861df 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
                     {
-                        if (auto xPropertySet = xStyle.query<XPropertySet>() )
-                            if 
(xPropertySet->getPropertyValue("IsPhysical").get<bool>())
-                                return true;
+                        Reference<XPropertySet> xPropertySet(xStyle, 
UNO_QUERY_THROW);
+                        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 219cf9ebf785..e794d9600e06 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
-                    if (auto xShapeProps = 
mXShape.query<css::beans::XPropertySet>() )
-                        xShapeProps->getPropertyValue("Aspect") >>= nAspect;
+                    css::uno::Reference< css::beans::XPropertySet > 
xShapeProps( mXShape, css::uno::UNO_QUERY_THROW );
+                    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
-                        if (auto xShapeProps = 
mXShape.query<css::beans::XPropertySet>() )
-                            xShapeProps->getPropertyValue("Aspect") >>= 
nAspect;
+                        css::uno::Reference< css::beans::XPropertySet > 
xShapeProps( mXShape, css::uno::UNO_QUERY_THROW );
+                        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 4f3b6a85048b..81d6b3c0176b 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -183,15 +183,29 @@ void AnnotationManagerImpl::init()
         TOOLS_WARN_EXCEPTION( "sd", 
"sd::AnnotationManagerImpl::AnnotationManagerImpl()" );
     }
 
-    if (auto xModel = 
mrBase.GetDocShell()->GetModel().query<XEventBroadcaster>() )
-        xModel->addEventListener( Reference<XEventListener>( this ) );
+    try
+    {
+        Reference<XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), 
UNO_QUERY_THROW );
+        Reference<XEventListener> xListener( this );
+        xModel->addEventListener( xListener );
+    }
+    catch( Exception& )
+    {
+    }
 }
 
 // WeakComponentImplHelper
 void AnnotationManagerImpl::disposing (std::unique_lock<std::mutex>&)
 {
-    if (auto xModel = 
mrBase.GetDocShell()->GetModel().query<XEventBroadcaster>() )
-        xModel->removeEventListener( Reference<XEventListener>( this ) );
+    try
+    {
+        Reference<XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), 
UNO_QUERY_THROW );
+        Reference<XEventListener> xListener( this );
+        xModel->removeEventListener( xListener );
+    }
+    catch( Exception& )
+    {
+    }
 
     removeListener();
     DisposeTags();
diff --git a/sd/source/ui/slideshow/slideshowviewimpl.cxx 
b/sd/source/ui/slideshow/slideshowviewimpl.cxx
index 4b476812a8d8..d6addc3f87fe 100644
--- a/sd/source/ui/slideshow/slideshowviewimpl.cxx
+++ b/sd/source/ui/slideshow/slideshowviewimpl.cxx
@@ -125,9 +125,10 @@ SlideShowView::SlideShowView( ShowWindow&     
rOutputWindow,
     {
         try
         {
-            if (auto xCanvasProps = getCanvas().query<beans::XPropertySet>() )
-                xCanvasProps->setPropertyValue("UnsafeScrolling",
-                    uno::Any( true ) );
+            Reference< beans::XPropertySet > xCanvasProps( getCanvas(),
+                                                           
uno::UNO_QUERY_THROW );
+            xCanvasProps->setPropertyValue("UnsafeScrolling",
+                uno::Any( true ) );
         }
         catch( uno::Exception& )
         {
diff --git a/sdext/source/minimizer/impoptimizer.cxx 
b/sdext/source/minimizer/impoptimizer.cxx
index 8cb61f01cb9c..72be9c666086 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 );
-        if (auto xDrawPagesSupplier = rxModel.query<XDrawPagesSupplier>() )
-            if (auto xDrawPages = 
xDrawPagesSupplier->getDrawPages().query<XDrawPages>() )
-                for( const auto& rxPage : vNonUsedPageList )
-                    xDrawPages->remove( rxPage );
+        Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, 
UNO_QUERY_THROW );
+        Reference< XDrawPages > xDrawPages( 
xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
+        for( const auto& rxPage : vNonUsedPageList )
+            xDrawPages->remove( rxPage );
     }
     catch( Exception& )
     {
@@ -544,12 +544,10 @@ static void DispatchURL( const Reference< 
XComponentContext >& xContext, const O
         aUrl.Complete = sURL;
         xURLTransformer->parseStrict( aUrl );
         Sequence< PropertyValue > aArgs;
-        if (auto xDispatchProvider = xFrame.query<XDispatchProvider>() )
-        {
-            Reference< XDispatch > xDispatch = 
xDispatchProvider->queryDispatch( aUrl, OUString(), 0 );  // "_self"
-            if ( xDispatch.is() )
-                xDispatch->dispatch( aUrl, aArgs );
-        }
+        Reference< XDispatchProvider > xDispatchProvider( xFrame, 
UNO_QUERY_THROW );
+        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 ab958b5cf851..1deef26ac059 100644
--- a/sdext/source/minimizer/optimizationstats.cxx
+++ b/sdext/source/minimizer/optimizationstats.cxx
@@ -74,9 +74,9 @@ void OptimizationStats::InitializeStatusValuesFromDocument( 
const Reference< XMo
 {
     try
     {
-        if (auto xDrawPagesSupplier = rxModel.query<XDrawPagesSupplier>() )
-            if (auto xDrawPages = 
xDrawPagesSupplier->getDrawPages().query<XDrawPages>() )
-                SetStatusValue( TK_Pages, Any( awt::Size( 0, 
xDrawPages->getCount() ) ) );
+        Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, 
UNO_QUERY_THROW );
+        Reference< XDrawPages > xDrawPages( 
xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
+        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 b87dc12f0406..49a8a5b9a08f 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -1109,8 +1109,11 @@ FileDialogHelper_Impl::FileDialogHelper_Impl(
     if ( mbExport )
     {
         mxFileDlg->setTitle( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) );
-        if (auto xCtrlAccess = mxFileDlg.query<XFilePickerControlAccess>() )
-            xCtrlAccess->enableControl( 
ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, true );
+        try {
+                css::uno::Reference < XFilePickerControlAccess > xCtrlAccess( 
mxFileDlg, UNO_QUERY_THROW );
+                xCtrlAccess->enableControl( 
ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, true );
+        }
+        catch( const Exception & ) { }
     }
 
     // Save a copy dialog
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 9178285b7de1..a5fb72251bf1 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
         {
-            if (auto xPropSet = 
rDocShell.GetStorage().query<beans::XPropertySet>() )
-                xPropSet->getPropertyValue("Version") >>= aVersion;
+            uno::Reference < beans::XPropertySet > xPropSet( 
rDocShell.GetStorage(), uno::UNO_QUERY_THROW );
+            xPropSet->getPropertyValue("Version") >>= aVersion;
         }
         catch( uno::Exception& )
         {
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 69290515b703..4044bc72fdef 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1197,8 +1197,8 @@ bool SfxObjectShell::SaveTo_Impl
             OUString aODFVersion;
             try
             {
-                if (auto xPropSet = GetStorage().query<beans::XPropertySet>() )
-                    xPropSet->getPropertyValue("Version") >>= aODFVersion;
+                uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), 
uno::UNO_QUERY_THROW );
+                xPropSet->getPropertyValue("Version") >>= aODFVersion;
             }
             catch( uno::Exception& )
             {}
@@ -1375,9 +1375,9 @@ bool SfxObjectShell::SaveTo_Impl
 
                 try
                 {
-                    if (auto xProps = 
rMedium.GetStorage().query<beans::XPropertySet>() )
-                        xProps->setPropertyValue("MediaType",
-                                                uno::Any( aDataFlavor.MimeType 
) );
+                    uno::Reference< beans::XPropertySet > xProps( 
rMedium.GetStorage(), uno::UNO_QUERY_THROW );
+                    xProps->setPropertyValue("MediaType",
+                                            uno::Any( aDataFlavor.MimeType ) );
                 }
                 catch( uno::Exception& )
                 {
@@ -1591,8 +1591,8 @@ bool SfxObjectShell::SaveTo_Impl
                 OUString aVersion;
                 try
                 {
-                    if (auto xPropSet = 
rMedium.GetStorage().query<beans::XPropertySet>() )
-                        xPropSet->getPropertyValue("Version") >>= aVersion;
+                    uno::Reference < beans::XPropertySet > xPropSet( 
rMedium.GetStorage(), uno::UNO_QUERY_THROW );
+                    xPropSet->getPropertyValue("Version") >>= aVersion;
                 }
                 catch( uno::Exception& )
                 {
@@ -1817,16 +1817,14 @@ bool SfxObjectShell::ConnectTmpStorage_Impl(
         try
         {
             // the empty argument means that the storage will create temporary 
stream itself
-            if (auto xOptStorage = xStorage.query<embed::XOptimizedStorage>() )
-            {
-                xOptStorage->writeAndAttachToStream( uno::Reference< 
io::XStream >() );
+            uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, 
uno::UNO_QUERY_THROW );
+            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& )
         {
@@ -1851,10 +1849,20 @@ bool SfxObjectShell::ConnectTmpStorage_Impl(
                 pImpl->aBasicManager.setStorage( xTmpStorage );
 
                 // Get rid of this workaround after issue i113914 is fixed
-                if (auto xBasicLibraries = 
pImpl->xBasicLibraries.query<script::XStorageBasedLibraryContainer>() )
+                try
+                {
+                    uno::Reference< script::XStorageBasedLibraryContainer > 
xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY_THROW );
                     xBasicLibraries->setRootStorage( xTmpStorage );
-                if (auto xDialogLibraries = 
pImpl->xDialogLibraries.query<script::XStorageBasedLibraryContainer>() )
+                }
+                catch( uno::Exception& )
+                {}
+                try
+                {
+                    uno::Reference< script::XStorageBasedLibraryContainer > 
xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY_THROW );
                     xDialogLibraries->setRootStorage( xTmpStorage );
+                }
+                catch( uno::Exception& )
+                {}
             }
         }
         catch( uno::Exception& )
@@ -2005,10 +2013,20 @@ bool SfxObjectShell::DoSaveCompleted( SfxMedium* 
pNewMed, bool bRegisterRecent )
         pImpl->aBasicManager.setStorage( xStorage );
 
         // Get rid of this workaround after issue i113914 is fixed
-        if (auto xBasicLibraries = 
pImpl->xBasicLibraries.query<script::XStorageBasedLibraryContainer>() )
+        try
+        {
+            uno::Reference< script::XStorageBasedLibraryContainer > 
xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY_THROW );
             xBasicLibraries->setRootStorage( xStorage );
-        if (auto xDialogLibraries = 
pImpl->xDialogLibraries.query<script::XStorageBasedLibraryContainer>() )
+        }
+        catch( uno::Exception& )
+        {}
+        try
+        {
+            uno::Reference< script::XStorageBasedLibraryContainer > 
xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY_THROW );
             xDialogLibraries->setRootStorage( xStorage );
+        }
+        catch( uno::Exception& )
+        {}
     }
     else
     {
@@ -3432,9 +3450,9 @@ static bool StoragesOfUnknownMediaTypeAreCopied_Impl( 
const uno::Reference< embe
 
                 try
                 {
-                    if (auto xOptStorage = 
xSource.query<embed::XOptimizedStorage>() )
-                        bGotMediaType =
-                            ( xOptStorage->getElementPropertyValue( 
rSubElement, aMediaTypePropName ) >>= aMediaType );
+                    uno::Reference< embed::XOptimizedStorage > xOptStorage( 
xSource, uno::UNO_QUERY_THROW );
+                    bGotMediaType =
+                        ( xOptStorage->getElementPropertyValue( rSubElement, 
aMediaTypePropName ) >>= aMediaType );
                 }
                 catch( uno::Exception& )
                 {}
@@ -3575,8 +3593,8 @@ bool SfxObjectShell::CopyStoragesOfUnknownMediaType(const 
uno::Reference< embed:
 
                 try
                 {
-                    if (auto xOptStorage = 
xSource.query<embed::XOptimizedStorage>() )
-                        bGotMediaType = 
(xOptStorage->getElementPropertyValue(rSubElement, aMediaTypePropName)
+                    uno::Reference< embed::XOptimizedStorage > xOptStorage( 
xSource, uno::UNO_QUERY_THROW );
+                    bGotMediaType = 
(xOptStorage->getElementPropertyValue(rSubElement, aMediaTypePropName)
                            >>= aMediaType);
                 }
                 catch( uno::Exception& )
diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx 
b/sot/source/unoolestorage/xolesimplestorage.cxx
index a79e24f48da5..46b82b2b538e 100644
--- a/sot/source/unoolestorage/xolesimplestorage.cxx
+++ b/sot/source/unoolestorage/xolesimplestorage.cxx
@@ -95,8 +95,13 @@ OLESimpleStorage::OLESimpleStorage(
 
         if ( xInputStream.is() )
         {
-            if (auto xSeek = xInputStream.query<io::XSeekable>() )
+            try
+            {
+                uno::Reference< io::XSeekable > xSeek( xInputStream, 
uno::UNO_QUERY_THROW );
                 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 e127c1a55090..ba5494975695 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
     {
-        if (auto xPropSet = xModel.query<beans::XPropertySet>() )
-            if (auto xNamed = xPropSet->getPropertyValue( "NamedRanges" 
).query<container::XNameAccess>() )
-                xReferrer.set ( xNamed->getByName( sAddress ), uno::UNO_QUERY 
);
+        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 );
     }
     catch( uno::Exception& /*e*/ )
     {
diff --git a/svx/source/smarttags/SmartTagMgr.cxx 
b/svx/source/smarttags/SmartTagMgr.cxx
index ba3707652342..37b9bc935222 100644
--- a/svx/source/smarttags/SmartTagMgr.cxx
+++ b/svx/source/smarttags/SmartTagMgr.cxx
@@ -240,8 +240,13 @@ void SmartTagMgr::WriteConfiguration( const bool* 
pIsLabelTextWithSmartTags,
 
     if ( bCommit )
     {
-        if (auto xChangesBatch = 
mxConfigurationSettings.query<util::XChangesBatch>() )
-            xChangesBatch->commitChanges();
+        try
+        {
+            Reference< util::XChangesBatch >( mxConfigurationSettings, 
UNO_QUERY_THROW )->commitChanges();
+        }
+        catch ( css::uno::Exception& )
+        {
+        }
     }
 }
 
@@ -443,16 +448,25 @@ void SmartTagMgr::RegisterListener()
     {
         Reference<deployment::XExtensionManager> xExtensionManager(
                 deployment::ExtensionManager::get( mxContext ) );
-        if (auto xMB = xExtensionManager.query<util::XModifyBroadcaster>() )
-            xMB->addModifyListener( Reference< util::XModifyListener >( this ) 
);
+        Reference< util::XModifyBroadcaster > xMB ( xExtensionManager, 
UNO_QUERY_THROW );
+
+        Reference< util::XModifyListener > xListener( this );
+        xMB->addModifyListener( xListener );
     }
     catch ( uno::Exception& )
     {
     }
 
     // register as listener at configuration
-    if (auto xCN = mxConfigurationSettings.query<util::XChangesNotifier>() )
-        xCN->addChangesListener( Reference< util::XChangesListener >( this ) );
+    try
+    {
+        Reference<util::XChangesNotifier> xCN( mxConfigurationSettings, 
UNO_QUERY_THROW );
+        Reference< util::XChangesListener > xListener( this );
+        xCN->addChangesListener( xListener );
+    }
+    catch ( uno::Exception& )
+    {
+    }
 }
 
 typedef std::pair < const OUString, ActionReference > SmartTagMapElement;
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index ea0ede8c0f38..0d862f8964f8 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -2791,8 +2791,14 @@ 
SvxLineWindow_Impl::SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::W
     , m_xLineStyleLbWin(new weld::CustomWeld(*m_xBuilder, "valueset", 
*m_xLineStyleLb))
     , m_bIsWriter(false)
 {
-    if (auto xServices = 
m_xFrame->getController()->getModel().query<lang::XServiceInfo>())
+    try
+    {
+        Reference< lang::XServiceInfo > 
xServices(m_xFrame->getController()->getModel(), UNO_QUERY_THROW);
         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 2da0987c0b61..19c2a66ce1bb 100644
--- a/svx/source/xml/xmlxtimp.cxx
+++ b/svx/source/xml/xmlxtimp.cxx
@@ -475,8 +475,14 @@ bool SvxXMLXTableImport::load( const OUString &rPath, 
const OUString &rReferer,
         if (xGraphicHelper.is())
             xGraphicStorageHandler = xGraphicHelper.get();
 
-        if (auto xSeek = aParserInput.aInputStream.query<io::XSeekable>() )
+        try
+        {
+            uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, 
uno::UNO_QUERY_THROW );
             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 a3cb985d5c85..de94986797f3 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -623,12 +623,10 @@ void SwOLENode::BreakFileLink_Impl()
 
     try
     {
-        if (auto xLinkSupport = 
maOLEObj.GetOleRef().query<embed::XLinkageSupport>() )
-        {
-            xLinkSupport->breakLink( xStorage, 
maOLEObj.GetCurrentPersistName() );
-            DisconnectFileLink_Impl();
-            maLinkURL.clear();
-        }
+        uno::Reference< embed::XLinkageSupport > xLinkSupport( 
maOLEObj.GetOleRef(), uno::UNO_QUERY_THROW );
+        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 e264548e3c37..3bb108cbf22e 100644
--- a/sw/source/core/swg/SwXMLTextBlocks.cxx
+++ b/sw/source/core/swg/SwXMLTextBlocks.cxx
@@ -295,11 +295,9 @@ ErrCode SwXMLTextBlocks::StartPutBlock( const OUString& 
rShort, const OUString&
     {
         m_xRoot = m_xBlkRoot->openStorageElement( rPackageName, 
embed::ElementModes::READWRITE );
 
-        if (auto xRootProps = m_xRoot.query<beans::XPropertySet>() )
-        {
-            OUString aMime( SotExchange::GetFormatMimeType( 
SotClipboardFormatId::STARWRITER_8 ) );
-            xRootProps->setPropertyValue( "MediaType", uno::Any( aMime ) );
-        }
+        uno::Reference< beans::XPropertySet > xRootProps( m_xRoot, 
uno::UNO_QUERY_THROW );
+        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 d14a58badb60..e5265acc4fec 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -69,8 +69,15 @@ void SwChartHelper::DoUpdateAllCharts( SwDoc* pDoc )
             uno::Reference < embed::XEmbeddedObject > xIP = 
pONd->GetOLEObj().GetOleRef();
             if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
             {
-                if (auto xModif = 
xIP->getComponent().query<util::XModifiable>() )
+                try
+                {
+                    uno::Reference< util::XModifiable > xModif( 
xIP->getComponent(), uno::UNO_QUERY_THROW );
                     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 b302c91c9388..a5b0560c1c5a 100644
--- a/sw/source/filter/xml/wrtxml.cxx
+++ b/sw/source/filter/xml/wrtxml.cxx
@@ -307,8 +307,9 @@ ErrCode SwXMLWriter::Write_(const SfxItemSet* 
pMediumItemSet)
                 && Version != ODFVER_010_TEXT
                 && Version != ODFVER_011_TEXT)
             {
-                if (auto xDMA = 
xModelComp.query<rdf::XDocumentMetadataAccess>())
-                    xDMA->storeMetadataToStorage(m_xStg);
+                const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
+                    xModelComp, uno::UNO_QUERY_THROW);
+                xDMA->storeMetadataToStorage(m_xStg);
             }
         }
         catch (beans::UnknownPropertyException &)
diff --git a/toolkit/source/controls/grid/gridcontrol.cxx 
b/toolkit/source/controls/grid/gridcontrol.cxx
index bd4c12e692f8..0fb9e9695958 100644
--- a/toolkit/source/controls/grid/gridcontrol.cxx
+++ b/toolkit/source/controls/grid/gridcontrol.cxx
@@ -167,8 +167,15 @@ namespace
 {
     void lcl_dispose_nothrow( const Any& i_component )
     {
-        if (auto xComponent = i_component.query<XComponent>() )
+        try
+        {
+            const Reference< XComponent > xComponent( i_component, 
UNO_QUERY_THROW );
             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 37f72c701f73..6ef68a6a8845 100644
--- a/toolkit/source/hatchwindow/documentcloser.cxx
+++ b/toolkit/source/hatchwindow/documentcloser.cxx
@@ -124,8 +124,15 @@ IMPL_STATIC_LINK( MainThreadFrameCloserRequest, worker, 
void*, p, void )
             // ignore all the errors
         }
 
-        if (auto xCloseable = pMTRequest->m_xFrame.query<util::XCloseable>() )
+        try
+        {
+            uno::Reference< util::XCloseable > xCloseable( 
pMTRequest->m_xFrame, uno::UNO_QUERY_THROW );
             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 cf5dcb0e64ae..93b89532072d 100644
--- a/unotools/source/config/confignode.cxx
+++ b/unotools/source/config/confignode.cxx
@@ -146,8 +146,15 @@ namespace utl
     OUString OConfigurationNode::getLocalName() const
     {
         OUString sLocalName;
-        if (auto xNamed = m_xDirectAccess.query<XNamed>() )
+        try
+        {
+            Reference< XNamed > xNamed( m_xDirectAccess, UNO_QUERY_THROW );
             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 6c3f625dd76d..0b39db9172ef 100644
--- a/unotools/source/config/lingucfg.cxx
+++ b/unotools/source/config/lingucfg.cxx
@@ -1016,11 +1016,9 @@ uno::Sequence< OUString > 
SvtLinguConfig::GetDisabledDictionaries() const
     uno::Sequence< OUString > aResult;
     try
     {
-        if (auto xNA = GetMainUpdateAccess().query<container::XNameAccess>() )
-        {
-            xNA.set( xNA->getByName("ServiceManager"), uno::UNO_QUERY_THROW );
-            xNA->getByName( "DisabledDictionaries" ) >>= aResult;
-        }
+        uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), 
uno::UNO_QUERY_THROW );
+        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 4cfc3f125358..1e181e8813d6 100644
--- a/unotools/source/config/useroptions.cxx
+++ b/unotools/source/config/useroptions.cxx
@@ -117,8 +117,14 @@ void SvtUserOptions::ChangeListener::changesOccurred 
(util::ChangesEvent const&
 
 void SvtUserOptions::ChangeListener::disposing (lang::EventObject const& 
rSource)
 {
-    if (auto xChgNot = rSource.Source.query<util::XChangesNotifier>())
+    try
+    {
+        uno::Reference<util::XChangesNotifier> xChgNot(rSource.Source, 
uno::UNO_QUERY_THROW);
         xChgNot->removeChangesListener(this);
+    }
+    catch (uno::Exception&)
+    {
+    }
 }
 
 SvtUserOptions::Impl::Impl() :
diff --git a/vbahelper/source/msforms/vbauserform.cxx 
b/vbahelper/source/msforms/vbauserform.cxx
index 50ba5a39ad90..66aa6eff7198 100644
--- a/vbahelper/source/msforms/vbauserform.cxx
+++ b/vbahelper/source/msforms/vbauserform.cxx
@@ -88,12 +88,16 @@ ScVbaUserForm::Show(  )
     if ( !mbDispose )
         return;
 
-    if (auto xComp = m_xDialog.query<lang::XComponent>() )
+    try
     {
+        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 8f0ad989c197..56180a98fb6a 100644
--- a/vbahelper/source/vbahelper/vbacolorformat.cxx
+++ b/vbahelper/source/vbahelper/vbacolorformat.cxx
@@ -43,10 +43,14 @@ ScVbaColorFormat::ScVbaColorFormat( const uno::Reference< 
XHelperInterface >& xP
 {
     m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
     m_nFillFormatBackColor = 0;
-    if (auto xFillFormat = xInternalParent.query<ov::msforms::XFillFormat>() )
+    try
+    {
+        uno::Reference< ov::msforms::XFillFormat > xFillFormat( 
xInternalParent, uno::UNO_QUERY_THROW );
         m_pFillFormat = static_cast<ScVbaFillFormat*>( xFillFormat.get() );
-    else
+    }catch ( uno::RuntimeException& )
+    {
         m_pFillFormat = nullptr;
+    }
 }
 
 // Attribute
diff --git a/vbahelper/source/vbahelper/vbadocumentbase.cxx 
b/vbahelper/source/vbahelper/vbadocumentbase.cxx
index 5231a1497135..0a2cc5b8705b 100644
--- a/vbahelper/source/vbahelper/vbadocumentbase.cxx
+++ b/vbahelper/source/vbahelper/vbadocumentbase.cxx
@@ -192,11 +192,16 @@ VbaDocumentBase::Close( const uno::Any &rSaveArg, const 
uno::Any &rFileArg,
     if (bCloseable)
         return;
 
-    // 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>() )
+    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 );
         xDisposable->dispose();
+    }
+    catch(const uno::Exception&)
+    {
+    }
 }
 
 void
diff --git a/vbahelper/source/vbahelper/vbadocumentsbase.cxx 
b/vbahelper/source/vbahelper/vbadocumentsbase.cxx
index d35b4e3f83ed..6db5b5a4cac0 100644
--- a/vbahelper/source/vbahelper/vbadocumentsbase.cxx
+++ b/vbahelper/source/vbahelper/vbadocumentsbase.cxx
@@ -198,21 +198,24 @@ namespace {
 
 void lclSetupComponent( const uno::Reference< lang::XComponent >& rxComponent, 
bool bScreenUpdating, bool bInteractive )
 {
-    auto xModel = rxComponent.query<frame::XModel>();
-    if( !bScreenUpdating && xModel )
-        xModel->lockControllers();
+    if( !bScreenUpdating ) try
+    {
+        uno::Reference< frame::XModel >( rxComponent, uno::UNO_QUERY_THROW 
)->lockControllers();
+    }
+    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& )
-        {
-        }
+    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& )
+    {
+    }
 }
 
 } // namespace
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 4b7e91978128..6538f03d6ea4 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -4498,12 +4498,16 @@ void DomainMapper_Impl::PopShapeContext()
     // or anchored to a discarded header or footer
     if ( m_aAnchoredStack.top().bToRemove || m_bDiscardHeaderFooter )
     {
-        if (auto xDrawPageSupplier = 
m_xTextDocument.query<drawing::XDrawPageSupplier>())
+        try
         {
+            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 6b5ff87317a2..4df26105a37c 100644
--- a/writerfilter/source/dmapper/ModelEventListener.cxx
+++ b/writerfilter/source/dmapper/ModelEventListener.cxx
@@ -102,8 +102,14 @@ void ModelEventListener::notifyEvent( const 
document::EventObject& rEvent )
 
 void ModelEventListener::disposing( const lang::EventObject& rEvent )
 {
-    if (auto xEventBroadcaster = 
rEvent.Source.query<document::XEventBroadcaster>())
-        
xEventBroadcaster->removeEventListener(uno::Reference<document::XEventListener>(this));
+    try
+    {
+        uno::Reference<document::XEventBroadcaster>(rEvent.Source, 
uno::UNO_QUERY_THROW )->removeEventListener(
+            uno::Reference<document::XEventListener>(this));
+    }
+    catch( const uno::Exception& )
+    {
+    }
 }
 
 } //namespace writerfilter::dmapper
diff --git a/writerfilter/source/dmapper/OLEHandler.cxx 
b/writerfilter/source/dmapper/OLEHandler.cxx
index bfa6a7d37bdf..e0671c8a21b6 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:") );
 
         }
-        if (auto xComp = xEmbeddedResolver.query<lang::XComponent>() )
-            xComp->dispose();
+        uno::Reference< lang::XComponent > xComp( xEmbeddedResolver, 
uno::UNO_QUERY_THROW );
+        xComp->dispose();
         m_aURL = aURL;
     }
     catch( const uno::Exception& )
diff --git a/xmloff/source/chart/SchXMLTableContext.cxx 
b/xmloff/source/chart/SchXMLTableContext.cxx
index b13394b54fdb..b12f5886e69b 100644
--- a/xmloff/source/chart/SchXMLTableContext.cxx
+++ b/xmloff/source/chart/SchXMLTableContext.cxx
@@ -765,11 +765,9 @@ void SchXMLTableHelper::applyTableToInternalDataProvider(
     {
         try
         {
-            if (auto xProps = xChartDoc.query<beans::XPropertySet>() )
-            {
-                xProps->setPropertyValue( "DisableDataTableDialog", uno::Any( 
true ) );
-                xProps->setPropertyValue( "DisableComplexChartTypes", 
uno::Any( true ) );
-            }
+            Reference< beans::XPropertySet > xProps( xChartDoc, 
uno::UNO_QUERY_THROW );
+            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 f55edf062e74..980dd8e0572d 100644
--- a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
+++ b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
@@ -122,8 +122,14 @@ void XMLEmbeddedObjectImportContext::SetComponent( 
Reference< XComponent > const
     SvXMLImport *pFastHandler = dynamic_cast<SvXMLImport*>(xFilter.get());
     mxFastHandler = pFastHandler;
 
-    if (auto xModifiable2 = rComp.query<XModifiable2>() )
+    try
+    {
+        Reference < XModifiable2 > xModifiable2( rComp, UNO_QUERY_THROW );
         xModifiable2->disableSetModified();
+    }
+    catch( Exception& )
+    {
+    }
 
     Reference < XImporter > xImporter( mxFastHandler, UNO_QUERY );
     xImporter->setTargetDocument( rComp );
@@ -236,11 +242,15 @@ void 
XMLEmbeddedObjectImportContext::endFastElement(sal_Int32 nElement)
     mxFastHandler->endFastElement( nElement );
     mxFastHandler->endDocument();
 
-    if (auto xModifiable2 = xComp.query<XModifiable2>() )
+    try
     {
+        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 )

Reply via email to