From a2265e8faa099d9652efd12392c2877c2df1d1eb Mon Sep 17 00:00:00 2001 From: Hossein Date: Tue, 12 Mar 2024 10:21:32 +0100 Subject: [PATCH] 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 Reviewed-by: Hossein --- .../cxx/FirstLoadComponent.cxx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 #include #include -#include #include #include #include @@ -63,20 +62,21 @@ SAL_IMPLEMENT_MAIN() Reference desktop = xRemoteServiceManager->createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); Reference xComponentLoader - = Reference(desktop, UNO_QUERY); + = Reference(desktop, UNO_QUERY_THROW); Sequence loadProps(0); Reference xSpreadsheetComponent = xComponentLoader->loadComponentFromURL( "private:factory/scalc", "_blank", 0, loadProps); - Reference xSpreadsheetDocument(xSpreadsheetComponent, UNO_QUERY); + Reference xSpreadsheetDocument(xSpreadsheetComponent, + UNO_QUERY_THROW); Reference 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(sheet, UNO_QUERY); + Reference xSpreadsheet(sheet, UNO_QUERY_THROW); Reference 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 xCellProps(xCell, UNO_QUERY); + Reference xCellProps(xCell, UNO_QUERY_THROW); xCellProps->setPropertyValue("CellStyle", Any(OUString("Result"))); - Reference xSpreadsheetModel(xSpreadsheetComponent, UNO_QUERY); + Reference xSpreadsheetModel(xSpreadsheetComponent, UNO_QUERY_THROW); Reference xSpreadsheetController = xSpreadsheetModel->getCurrentController(); - Reference xSpreadsheetView(xSpreadsheetController, UNO_QUERY); + Reference xSpreadsheetView(xSpreadsheetController, UNO_QUERY_THROW); xSpreadsheetView->setActiveSheet(xSpreadsheet); // ********************************************************* @@ -118,7 +118,7 @@ SAL_IMPLEMENT_MAIN() // ********************************************************* // example for use of XEnumerationAccess - Reference xCellQuery(sheet, UNO_QUERY); + Reference xCellQuery(sheet, UNO_QUERY_THROW); Reference xFormulaCells = xCellQuery->queryContentCells((sal_Int16)CellFlags::FORMULA); Reference xFormulas = xFormulaCells->getCells(); @@ -126,8 +126,8 @@ SAL_IMPLEMENT_MAIN() while (xFormulaEnum->hasMoreElements()) { - Reference formulaCell(xFormulaEnum->nextElement(), UNO_QUERY); - Reference xCellAddress(formulaCell, UNO_QUERY); + Reference formulaCell(xFormulaEnum->nextElement(), UNO_QUERY_THROW); + Reference 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 << "\n"; return 1;