odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx | 22 +++++----- 1 file changed, 11 insertions(+), 11 deletions(-)
New commits: commit a2265e8faa099d9652efd12392c2877c2df1d1eb Author: Hossein <hoss...@libreoffice.org> AuthorDate: Tue Mar 12 10:21:32 2024 +0100 Commit: Hossein <hoss...@libreoffice.org> CommitDate: Wed Mar 13 00:57:06 2024 +0100 Use UNO_QUERY_THROW instead of UNO_QUERY Previously, in SDK examples, de-referencing was done unconditionally after obtaining a reference using UNO_QUERY. Now, we use UNO_QUERY_THROW instead, to make sure cases where exceptions may occure can be handled correctly. Change-Id: Ic73ba3cfcad914dabb7ae3736ad1ae2bd6cc15bd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164682 Tested-by: Hossein <hoss...@libreoffice.org> Reviewed-by: Hossein <hoss...@libreoffice.org> diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx index 9ac650ad49af..79493e2e5ed0 100644 --- a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx @@ -30,7 +30,6 @@ #include <com/sun/star/sheet/XSpreadsheetView.hpp> #include <com/sun/star/table/CellVertJustify.hpp> #include <com/sun/star/table/XCell.hpp> -#include <com/sun/star/uno/RuntimeException.hpp> #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Type.hxx> #include <com/sun/star/uno/XComponentContext.hpp> @@ -63,20 +62,21 @@ SAL_IMPLEMENT_MAIN() Reference<XInterface> desktop = xRemoteServiceManager->createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); Reference<XComponentLoader> xComponentLoader - = Reference<XComponentLoader>(desktop, UNO_QUERY); + = Reference<XComponentLoader>(desktop, UNO_QUERY_THROW); Sequence<PropertyValue> loadProps(0); Reference<XComponent> xSpreadsheetComponent = xComponentLoader->loadComponentFromURL( "private:factory/scalc", "_blank", 0, loadProps); - Reference<XSpreadsheetDocument> xSpreadsheetDocument(xSpreadsheetComponent, UNO_QUERY); + Reference<XSpreadsheetDocument> xSpreadsheetDocument(xSpreadsheetComponent, + UNO_QUERY_THROW); Reference<XSpreadsheets> xSpreadsheets = xSpreadsheetDocument->getSheets(); xSpreadsheets->insertNewByName("MySheet", (sal_Int16)0); Type elemType = xSpreadsheets->getElementType(); std::cout << elemType.getTypeName() << std::endl; Any sheet = xSpreadsheets->getByName("MySheet"); - Reference<XSpreadsheet> xSpreadsheet(sheet, UNO_QUERY); + Reference<XSpreadsheet> xSpreadsheet(sheet, UNO_QUERY_THROW); Reference<XCell> xCell = xSpreadsheet->getCellByPosition(0, 0); xCell->setValue(21); @@ -85,12 +85,12 @@ SAL_IMPLEMENT_MAIN() xCell = xSpreadsheet->getCellByPosition(0, 2); xCell->setFormula("=sum(A1:A2)"); - Reference<XPropertySet> xCellProps(xCell, UNO_QUERY); + Reference<XPropertySet> xCellProps(xCell, UNO_QUERY_THROW); xCellProps->setPropertyValue("CellStyle", Any(OUString("Result"))); - Reference<XModel> xSpreadsheetModel(xSpreadsheetComponent, UNO_QUERY); + Reference<XModel> xSpreadsheetModel(xSpreadsheetComponent, UNO_QUERY_THROW); Reference<XController> xSpreadsheetController = xSpreadsheetModel->getCurrentController(); - Reference<XSpreadsheetView> xSpreadsheetView(xSpreadsheetController, UNO_QUERY); + Reference<XSpreadsheetView> xSpreadsheetView(xSpreadsheetController, UNO_QUERY_THROW); xSpreadsheetView->setActiveSheet(xSpreadsheet); // ********************************************************* @@ -118,7 +118,7 @@ SAL_IMPLEMENT_MAIN() // ********************************************************* // example for use of XEnumerationAccess - Reference<XCellRangesQuery> xCellQuery(sheet, UNO_QUERY); + Reference<XCellRangesQuery> xCellQuery(sheet, UNO_QUERY_THROW); Reference<XSheetCellRanges> xFormulaCells = xCellQuery->queryContentCells((sal_Int16)CellFlags::FORMULA); Reference<XEnumerationAccess> xFormulas = xFormulaCells->getCells(); @@ -126,8 +126,8 @@ SAL_IMPLEMENT_MAIN() while (xFormulaEnum->hasMoreElements()) { - Reference<XCell> formulaCell(xFormulaEnum->nextElement(), UNO_QUERY); - Reference<XCellAddressable> xCellAddress(formulaCell, UNO_QUERY); + Reference<XCell> formulaCell(xFormulaEnum->nextElement(), UNO_QUERY_THROW); + Reference<XCellAddressable> xCellAddress(formulaCell, UNO_QUERY_THROW); if (xCellAddress.is()) { std::cout << "Formula cell in column " << xCellAddress->getCellAddress().Column @@ -136,7 +136,7 @@ SAL_IMPLEMENT_MAIN() } } } - catch (RuntimeException& e) + catch (Exception& e) { std::cerr << e.Message << " "; return 1;