use less exception throwing for flow control

Change-Id: I7ad023479229f89918e588eb8dc7431b5830b45d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171813
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2024-08-13 11:35:17 +02:00
parent cd72aca086
commit ade52eb721
14 changed files with 213 additions and 132 deletions

View File

@ -895,9 +895,15 @@ bool SvtLinguConfig::GetElementNamesFor(
bool bSuccess = false;
try
{
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName( rNodeName ), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName( rNodeName ), uno::UNO_QUERY );
if (!xNA)
return false;
rElementNames = xNA->getElementNames();
bSuccess = true;
}
@ -917,10 +923,18 @@ bool SvtLinguConfig::GetSupportedDictionaryFormatsFor(
bool bSuccess = false;
try
{
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName( rSetEntry ), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName( rSetEntry ), uno::UNO_QUERY );
if (!xNA)
return false;
if (xNA->getByName( u"SupportedDictionaryFormats"_ustr ) >>= rFormatList)
bSuccess = true;
DBG_ASSERT( rFormatList.hasElements(), "supported dictionary format list is empty" );
@ -938,10 +952,18 @@ bool SvtLinguConfig::GetLocaleListFor( const OUString &rSetName, const OUString
bool bSuccess = false;
try
{
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName( rSetEntry ), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName( rSetEntry ), uno::UNO_QUERY );
if (!xNA)
return false;
if (xNA->getByName( u"Locales"_ustr ) >>= rLocaleList)
bSuccess = true;
DBG_ASSERT( rLocaleList.hasElements(), "Locale list is empty" );
@ -1027,8 +1049,12 @@ 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(u"ServiceManager"_ustr), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY );
if (!xNA)
return aResult;
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY );
if (!xNA)
return aResult;
xNA->getByName( u"DisabledDictionaries"_ustr ) >>= aResult;
}
catch (uno::Exception &)
@ -1084,28 +1110,27 @@ std::vector< SvtLinguConfigDictionaryEntry > SvtLinguConfig::GetActiveDictionari
uno::Reference< util::XChangesBatch > const & SvtLinguConfig::GetMainUpdateAccess() const
{
if (!m_xMainUpdateAccess.is())
if (m_xMainUpdateAccess)
return m_xMainUpdateAccess;
try
{
try
{
// get configuration provider
uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider =
configuration::theDefaultProvider::get( xContext );
// get configuration provider
uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider =
configuration::theDefaultProvider::get( xContext );
// get configuration update access
beans::PropertyValue aValue;
aValue.Name = "nodepath";
aValue.Value <<= u"org.openoffice.Office.Linguistic"_ustr;
uno::Sequence< uno::Any > aProps{ uno::Any(aValue) };
m_xMainUpdateAccess.set(
xConfigurationProvider->createInstanceWithArguments(
u"com.sun.star.configuration.ConfigurationUpdateAccess"_ustr, aProps),
uno::UNO_QUERY_THROW );
}
catch (uno::Exception &)
{
}
// get configuration update access
beans::PropertyValue aValue;
aValue.Name = "nodepath";
aValue.Value <<= u"org.openoffice.Office.Linguistic"_ustr;
uno::Sequence< uno::Any > aProps{ uno::Any(aValue) };
m_xMainUpdateAccess.set(
xConfigurationProvider->createInstanceWithArguments(
u"com.sun.star.configuration.ConfigurationUpdateAccess"_ustr, aProps),
uno::UNO_QUERY );
}
catch (uno::Exception &)
{
}
return m_xMainUpdateAccess;
@ -1186,9 +1211,15 @@ bool SvtLinguConfig::HasGrammarChecker() const
try
{
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName(u"GrammarCheckerList"_ustr), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName(u"ServiceManager"_ustr), uno::UNO_QUERY );
if (!xNA)
return false;
xNA.set( xNA->getByName(u"GrammarCheckerList"_ustr), uno::UNO_QUERY );
if (!xNA)
return false;
uno::Sequence< OUString > aElementNames( xNA->getElementNames() );
bRes = aElementNames.hasElements();

View File

@ -121,8 +121,9 @@ void SvtUserOptions::ChangeListener::disposing (lang::EventObject const& rSource
{
try
{
uno::Reference<util::XChangesNotifier> xChgNot(rSource.Source, uno::UNO_QUERY_THROW);
xChgNot->removeChangesListener(this);
uno::Reference<util::XChangesNotifier> xChgNot(rSource.Source, uno::UNO_QUERY);
if (xChgNot)
xChgNot->removeChangesListener(this);
}
catch (uno::Exception&)
{

View File

@ -301,21 +301,24 @@ ScVbaControl::getControlSource()
// dependent parts
OUString sControlSource;
uno::Reference< form::binding::XBindableValue > xBindable( m_xProps, uno::UNO_QUERY );
if ( xBindable.is() )
if ( !xBindable )
return sControlSource;
try
{
uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
if ( !xFac )
return sControlSource;
uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( u"com.sun.star.table.CellAddressConversion"_ustr ), uno::UNO_QUERY );
uno::Reference< beans::XPropertySet > xProps( xBindable->getValueBinding(), uno::UNO_QUERY);
if ( !xProps )
return sControlSource;
table::CellAddress aAddress;
xProps->getPropertyValue( u"BoundCell"_ustr ) >>= aAddress;
xConvertor->setPropertyValue( u"Address"_ustr , uno::Any( aAddress ) );
xConvertor->getPropertyValue( u"XLA1Representation"_ustr ) >>= sControlSource;
}
catch(const uno::Exception&)
{
try
{
uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( u"com.sun.star.table.CellAddressConversion"_ustr ), uno::UNO_QUERY );
uno::Reference< beans::XPropertySet > xProps( xBindable->getValueBinding(), uno::UNO_QUERY_THROW );
table::CellAddress aAddress;
xProps->getPropertyValue( u"BoundCell"_ustr ) >>= aAddress;
xConvertor->setPropertyValue( u"Address"_ustr , uno::Any( aAddress ) );
xConvertor->getPropertyValue( u"XLA1Representation"_ustr ) >>= sControlSource;
}
catch(const uno::Exception&)
{
}
}
return sControlSource;
}
@ -364,22 +367,25 @@ ScVbaControl::getRowSource()
{
OUString sRowSource;
uno::Reference< form::binding::XListEntrySink > xListSink( m_xProps, uno::UNO_QUERY );
if ( xListSink.is() )
if ( !xListSink )
return sRowSource;
try
{
try
{
uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW );
uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( u"com.sun.star.table.CellRangeAddressConversion"_ustr ), uno::UNO_QUERY );
uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY );
if ( !xFac )
return sRowSource;
uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( u"com.sun.star.table.CellRangeAddressConversion"_ustr ), uno::UNO_QUERY );
uno::Reference< beans::XPropertySet > xProps( xListSink->getListEntrySource(), uno::UNO_QUERY_THROW );
table::CellRangeAddress aAddress;
xProps->getPropertyValue( u"CellRange"_ustr ) >>= aAddress;
xConvertor->setPropertyValue( u"Address"_ustr , uno::Any( aAddress ) );
xConvertor->getPropertyValue( u"XLA1Representation"_ustr ) >>= sRowSource;
}
catch(const uno::Exception&)
{
}
uno::Reference< beans::XPropertySet > xProps( xListSink->getListEntrySource(), uno::UNO_QUERY );
if ( !xProps )
return sRowSource;
table::CellRangeAddress aAddress;
xProps->getPropertyValue( u"CellRange"_ustr ) >>= aAddress;
xConvertor->setPropertyValue( u"Address"_ustr , uno::Any( aAddress ) );
xConvertor->getPropertyValue( u"XLA1Representation"_ustr ) >>= sRowSource;
}
catch(const uno::Exception&)
{
}
return sRowSource;
}

View File

@ -90,10 +90,13 @@ ScVbaUserForm::Show( )
try
{
uno::Reference< lang::XComponent > xComp( m_xDialog, uno::UNO_QUERY_THROW );
m_xDialog = nullptr;
xComp->dispose();
mbDispose = false;
uno::Reference< lang::XComponent > xComp( m_xDialog, uno::UNO_QUERY );
if (xComp)
{
m_xDialog = nullptr;
xComp->dispose();
mbDispose = false;
}
}
catch( uno::Exception& )
{

View File

@ -141,32 +141,35 @@ VbaDocumentBase::Close( const uno::Any &rSaveArg, const uno::Any &rFileArg,
xModifiable->setModified( false );
// first try to close the document using UI dispatch functionality
bool bUIClose = false;
try
{
uno::Reference< frame::XController > xController( getModel()->getCurrentController(), uno::UNO_SET_THROW );
uno::Reference< frame::XDispatchProvider > xDispatchProvider( xController->getFrame(), uno::UNO_QUERY_THROW );
uno::Reference< frame::XController > xController( getModel()->getCurrentController() );
if (xController)
{
uno::Reference< frame::XDispatchProvider > xDispatchProvider( xController->getFrame(), uno::UNO_QUERY );
uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() );
if (xDispatchProvider && xServiceManager)
{
uno::Reference< util::XURLTransformer > xURLTransformer( util::URLTransformer::create(mxContext) );
uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
uno::Reference< util::XURLTransformer > xURLTransformer( util::URLTransformer::create(mxContext) );
util::URL aURL;
aURL.Complete = ".uno:CloseDoc";
xURLTransformer->parseStrict( aURL );
util::URL aURL;
aURL.Complete = ".uno:CloseDoc";
xURLTransformer->parseStrict( aURL );
uno::Reference< css::frame::XDispatch > xDispatch(
xDispatchProvider->queryDispatch( aURL, u"_self"_ustr , 0 ),
uno::UNO_SET_THROW );
xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
bUIClose = true;
uno::Reference< css::frame::XDispatch > xDispatch(
xDispatchProvider->queryDispatch( aURL, u"_self"_ustr , 0 ) );
if (xDispatch)
{
xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
return;
}
}
}
}
catch(const uno::Exception&)
{
}
if ( bUIClose )
return;
// if it is not possible to use UI dispatch, try to close the model directly
bool bCloseable = false;
uno::Reference< frame::XModel > xModel = getModel();
@ -196,8 +199,8 @@ VbaDocumentBase::Close( const uno::Any &rSaveArg, const uno::Any &rFileArg,
// 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();
if (xModel)
xModel->dispose();
}
catch(const uno::Exception&)
{
@ -277,13 +280,20 @@ VbaDocumentBase::getVBProject()
{
if( !mxVBProject.is() ) try
{
uno::Reference< XApplicationBase > xApp( Application(), uno::UNO_QUERY_THROW );
uno::Reference< XInterface > xVBE( xApp->getVBE(), uno::UNO_QUERY_THROW );
uno::Sequence< uno::Any > aArgs{ uno::Any(xVBE), // the VBE
uno::Any(getModel()) }; // document model for script container access
uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
mxVBProject = xServiceManager->createInstanceWithArgumentsAndContext(
u"ooo.vba.vbide.VBProject"_ustr, aArgs, mxContext );
uno::Reference< XApplicationBase > xApp( Application(), uno::UNO_QUERY );
if (xApp)
{
uno::Reference< XInterface > xVBE( xApp->getVBE(), uno::UNO_QUERY );
if (xVBE)
{
uno::Sequence< uno::Any > aArgs{ uno::Any(xVBE), // the VBE
uno::Any(getModel()) }; // document model for script container access
uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() );
if (xServiceManager)
mxVBProject = xServiceManager->createInstanceWithArgumentsAndContext(
u"ooo.vba.vbide.VBProject"_ustr, aArgs, mxContext );
}
}
}
catch(const uno::Exception&)
{

View File

@ -206,12 +206,23 @@ void lclSetupComponent( const uno::Reference< lang::XComponent >& rxComponent, b
{
}
if( !bInteractive ) try
if( bInteractive )
return;
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 );
uno::Reference< frame::XModel > xModel( rxComponent, uno::UNO_QUERY );
if (!xModel)
return;
uno::Reference< frame::XController > xController( xModel->getCurrentController() );
if (!xController)
return;
uno::Reference< frame::XFrame > xFrame( xController->getFrame() );
if (!xFrame)
return;
uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow() );
if (!xWindow)
return;
xWindow->setEnable( false );
}
catch( uno::Exception& )
{

View File

@ -1078,7 +1078,9 @@ uno::Reference< XHelperInterface > getVBADocument( const uno::Reference< frame::
uno::Reference< XHelperInterface > xIf;
try
{
uno::Reference< beans::XPropertySet > xDocProps( xModel, uno::UNO_QUERY_THROW );
uno::Reference< beans::XPropertySet > xDocProps( xModel, uno::UNO_QUERY );
if (!xDocProps)
return xIf;
OUString aCodeName;
xDocProps->getPropertyValue( u"CodeName"_ustr ) >>= aCodeName;
xIf = getUnoDocModule( aCodeName, getSfxObjShell( xModel ) );

View File

@ -142,7 +142,9 @@ bool WpftLoader::impl_load()
}
const uno::Reference<document::XExtendedFilterDetection> xDetector(m_xFilter,
uno::UNO_QUERY_THROW);
uno::UNO_QUERY);
if (!xDetector)
return false;
const OUString aTypeName(xDetector->detect(aDescriptor));
if (aTypeName.isEmpty())

View File

@ -59,25 +59,28 @@ uno::Reference<io::XInputStream> findStream(ucbhelper::Content& rContent, std::u
{
const uno::Reference<sdbc::XResultSet> xResultSet(
rContent.createCursor(lPropNames, ucbhelper::INCLUDE_DOCUMENTS_ONLY));
if (xResultSet->first())
if (!xResultSet->first())
return xInputStream;
const uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY);
if (!xContentAccess)
return xInputStream;
const uno::Reference<sdbc::XRow> xRow(xResultSet, uno::UNO_QUERY);
if (!xRow)
return xInputStream;
do
{
const uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet,
uno::UNO_QUERY_THROW);
const uno::Reference<sdbc::XRow> xRow(xResultSet, uno::UNO_QUERY_THROW);
do
const OUString aTitle(xRow->getString(1));
if (aTitle == rName)
{
const OUString aTitle(xRow->getString(1));
if (aTitle == rName)
{
const uno::Reference<ucb::XContent> xSubContent(xContentAccess->queryContent());
ucbhelper::Content aSubContent(xSubContent,
uno::Reference<ucb::XCommandEnvironment>(),
comphelper::getProcessComponentContext());
xInputStream = aSubContent.openStream();
break;
}
} while (xResultSet->next());
}
const uno::Reference<ucb::XContent> xSubContent(xContentAccess->queryContent());
ucbhelper::Content aSubContent(xSubContent,
uno::Reference<ucb::XCommandEnvironment>(),
comphelper::getProcessComponentContext());
xInputStream = aSubContent.openStream();
break;
}
} while (xResultSet->next());
}
catch (const uno::RuntimeException&)
{

View File

@ -369,7 +369,9 @@ Reference<XInputStream> ZipStorageImpl::createStream(const OUString& rPath)
try
{
const Reference<XInputStream> xInputStream(mxContainer->getByName(rPath), UNO_QUERY_THROW);
const Reference<XInputStream> xInputStream(mxContainer->getByName(rPath), UNO_QUERY);
if (!xInputStream)
return xStream;
const Reference<XSeekable> xSeekable(xInputStream, UNO_QUERY);
if (xSeekable.is())

View File

@ -1640,8 +1640,9 @@ void SchXMLExportHelper_Impl::exportTable()
try
{
bool bProtected = false;
Reference< beans::XPropertySet > xProps( mrExport.GetModel(), uno::UNO_QUERY_THROW );
if ( ( xProps->getPropertyValue(u"DisableDataTableDialog"_ustr) >>= bProtected ) &&
Reference< beans::XPropertySet > xProps( mrExport.GetModel(), uno::UNO_QUERY );
if ( xProps &&
( xProps->getPropertyValue(u"DisableDataTableDialog"_ustr) >>= bProtected ) &&
bProtected )
{
mrExport.AddAttribute( XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE );

View File

@ -762,9 +762,12 @@ void SchXMLTableHelper::applyTableToInternalDataProvider(
{
try
{
Reference< beans::XPropertySet > xProps( xChartDoc, uno::UNO_QUERY_THROW );
xProps->setPropertyValue( u"DisableDataTableDialog"_ustr, uno::Any( true ) );
xProps->setPropertyValue( u"DisableComplexChartTypes"_ustr, uno::Any( true ) );
Reference< beans::XPropertySet > xProps( xChartDoc, uno::UNO_QUERY );
if (xProps)
{
xProps->setPropertyValue( u"DisableDataTableDialog"_ustr, uno::Any( true ) );
xProps->setPropertyValue( u"DisableComplexChartTypes"_ustr, uno::Any( true ) );
}
}
catch ( uno::Exception& )
{

View File

@ -123,8 +123,9 @@ void XMLEmbeddedObjectImportContext::SetComponent( Reference< XComponent > const
try
{
Reference < XModifiable2 > xModifiable2( rComp, UNO_QUERY_THROW );
xModifiable2->disableSetModified();
Reference < XModifiable2 > xModifiable2( rComp, UNO_QUERY );
if (xModifiable2)
xModifiable2->disableSetModified();
}
catch( Exception& )
{
@ -243,9 +244,12 @@ void XMLEmbeddedObjectImportContext::endFastElement(sal_Int32 nElement)
try
{
Reference < XModifiable2 > xModifiable2( xComp, UNO_QUERY_THROW );
xModifiable2->enableSetModified();
xModifiable2->setModified( true ); // trigger new replacement image generation
Reference < XModifiable2 > xModifiable2( xComp, UNO_QUERY );
if (xModifiable2)
{
xModifiable2->enableSetModified();
xModifiable2->setModified( true ); // trigger new replacement image generation
}
}
catch( Exception& )
{

View File

@ -46,7 +46,9 @@ void SdXMLDescriptionContext::endFastElement(sal_Int32 )
try
{
uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY_THROW);
uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
if (!xPropSet)
return;
if( (mnElement & TOKEN_MASK) == XML_TITLE)
{
xPropSet->setPropertyValue(u"Title"_ustr, Any(msText));