diff options
author | Hossein <hossein@libreoffice.org> | 2024-03-12 10:21:32 +0100 |
---|---|---|
committer | Hossein <hossein@libreoffice.org> | 2024-03-13 00:57:06 +0100 |
commit | a2265e8faa099d9652efd12392c2877c2df1d1eb (patch) | |
tree | 83ee67f5543664687294c585c3e726795b077869 /odk/examples | |
parent | 1f93803aa1fdca7ac83f4801b8a6e866908a3bd8 (diff) |
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 <hossein@libreoffice.org>
Reviewed-by: Hossein <hossein@libreoffice.org>
Diffstat (limited to 'odk/examples')
-rw-r--r-- | odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/cxx/FirstLoadComponent.cxx | 22 |
1 files 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 <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 << "\n"; return 1; |