summaryrefslogtreecommitdiff
path: root/vbahelper/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-08-13 11:35:17 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-08-13 19:36:37 +0200
commitade52eb721524e3717f47ccd97e0aa2018b96cb0 (patch)
tree7293c6b5bf077d14479ca3f714cf0a1942d1f709 /vbahelper/source
parentcd72aca086ff84467d51f6864c58648c3322c53f (diff)
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>
Diffstat (limited to 'vbahelper/source')
-rw-r--r--vbahelper/source/msforms/vbacontrol.cxx64
-rw-r--r--vbahelper/source/msforms/vbauserform.cxx11
-rw-r--r--vbahelper/source/vbahelper/vbadocumentbase.cxx66
-rw-r--r--vbahelper/source/vbahelper/vbadocumentsbase.cxx21
-rw-r--r--vbahelper/source/vbahelper/vbahelper.cxx4
5 files changed, 99 insertions, 67 deletions
diff --git a/vbahelper/source/msforms/vbacontrol.cxx b/vbahelper/source/msforms/vbacontrol.cxx
index 3b7976cf574c..c144babe5512 100644
--- a/vbahelper/source/msforms/vbacontrol.cxx
+++ b/vbahelper/source/msforms/vbacontrol.cxx
@@ -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
+ {
+ 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 );
+ 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&)
{
- 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< 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&)
- {
- }
}
return sRowSource;
}
diff --git a/vbahelper/source/msforms/vbauserform.cxx b/vbahelper/source/msforms/vbauserform.cxx
index 663a51d7cf8f..8f99b6f39bec 100644
--- a/vbahelper/source/msforms/vbauserform.cxx
+++ b/vbahelper/source/msforms/vbauserform.cxx
@@ -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& )
{
diff --git a/vbahelper/source/vbahelper/vbadocumentbase.cxx b/vbahelper/source/vbahelper/vbadocumentbase.cxx
index 80cd896cb44d..ff9ef8c1bc72 100644
--- a/vbahelper/source/vbahelper/vbadocumentbase.cxx
+++ b/vbahelper/source/vbahelper/vbadocumentbase.cxx
@@ -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< 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 );
-
- 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< 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) );
+
+ util::URL aURL;
+ aURL.Complete = ".uno:CloseDoc";
+ xURLTransformer->parseStrict( aURL );
+
+ 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&)
{
diff --git a/vbahelper/source/vbahelper/vbadocumentsbase.cxx b/vbahelper/source/vbahelper/vbadocumentsbase.cxx
index 4821fc5c1c09..ec7694c59294 100644
--- a/vbahelper/source/vbahelper/vbadocumentsbase.cxx
+++ b/vbahelper/source/vbahelper/vbadocumentsbase.cxx
@@ -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& )
{
diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx
index d8d2818d4fb9..99494d8cc7e1 100644
--- a/vbahelper/source/vbahelper/vbahelper.cxx
+++ b/vbahelper/source/vbahelper/vbahelper.cxx
@@ -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 ) );