From c55873f3e72a05cf94dabd7109c99e4b66c4f5a6 Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Tue, 27 Sep 2016 07:09:35 +0200 Subject: Return early on error Change-Id: I963c069e27903e3d1a709ce0c17666a17f45f132 --- sc/source/ui/unoobj/dapiuno.cxx | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'sc/source/ui/unoobj/dapiuno.cxx') diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx index 982b085abf9a..677a6ae83b4b 100644 --- a/sc/source/ui/unoobj/dapiuno.cxx +++ b/sc/source/ui/unoobj/dapiuno.cxx @@ -2527,12 +2527,27 @@ Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( cons { SolarMutexGuard aGuard; - Reference< XDataPilotField > xRet; - OUString sNewDim; - if( !rItems.hasElements() ) throw IllegalArgumentException(); + Reference< XMembersAccess > xMembers = GetMembers(); + if (!xMembers.is()) + { + SAL_WARN("sc.ui", "Cannot access members of the field object."); + throw RuntimeException(); + } + + for (const OUString& aEntryName : rItems) + { + if (!xMembers->hasByName(aEntryName)) + { + SAL_WARN("sc.ui", "There is no member with that name: " + aEntryName + "."); + throw IllegalArgumentException(); + } + } + + Reference< XDataPilotField > xRet; + OUString sNewDim; ScDPObject* pDPObj = nullptr; if( ScDPSaveDimension* pDim = GetDPDimension( &pDPObj ) ) { @@ -2613,25 +2628,9 @@ Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( cons OUString aGroupName = pGroupDimension->CreateGroupName( ScGlobal::GetRscString(STR_PIVOT_GROUP) ); ScDPSaveGroupItem aGroup( aGroupName ); - Reference< XMembersAccess > xMembers = GetMembers(); - if (!xMembers.is()) - { - SAL_WARN("sc.ui", "Cannot access members of the field object."); - delete pNewGroupDim; - throw RuntimeException(); - } - for (sal_Int32 nEntry = 0; nEntry < rItems.getLength(); nEntry++) { OUString aEntryName(rItems[nEntry]); - - if (!xMembers->hasByName(aEntryName)) - { - SAL_WARN("sc.ui", "There is no member with that name: " + aEntryName + "."); - delete pNewGroupDim; - throw IllegalArgumentException(); - } - if ( pBaseGroupDim ) { // for each selected (intermediate) group, add all its items -- cgit