From d1b00bf1321bd01d499730b0e2ba1b0d2aec3474 Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Sat, 16 Aug 2025 13:55:33 +0100 Subject: [PATCH] Coding - Reducing relying on exceptions (#676) - Replaced try-catch blocks with explicit validation checks in PCDM_ReadWriter_1.cxx - Added division-by-zero protection in XSDRAWSTL.cxx using precision-based comparison - Improved error handling for integer parsing operations --- .../TKCDF/PCDM/PCDM_ReadWriter_1.cxx | 17 ++++++++--------- src/Draw/TKXSDRAWSTL/XSDRAWSTL/XSDRAWSTL.cxx | 9 ++++----- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ApplicationFramework/TKCDF/PCDM/PCDM_ReadWriter_1.cxx b/src/ApplicationFramework/TKCDF/PCDM/PCDM_ReadWriter_1.cxx index cff2929f01..2dbef896a3 100644 --- a/src/ApplicationFramework/TKCDF/PCDM/PCDM_ReadWriter_1.cxx +++ b/src/ApplicationFramework/TKCDF/PCDM/PCDM_ReadWriter_1.cxx @@ -259,14 +259,13 @@ Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter( { if (refUserInfo(i).Search(REFERENCE_COUNTER) != -1) { - try + TCollection_AsciiString aToken = refUserInfo(i).Token(" ", 2); + if (aToken.IsIntegerValue()) { - OCC_CATCH_SIGNALS theReferencesCounter = refUserInfo(i).Token(" ", 2).IntegerValue(); + theReferencesCounter = aToken.IntegerValue(); } - catch (Standard_Failure const&) + else { - // std::cout << "warning: could not read the reference counter in " << aFileName << - // std::endl; TCollection_ExtendedString aMsg("Warning: "); aMsg = aMsg.Cat("could not read the reference counter in ").Cat(aFileName).Cat("\0"); if (!theMsgDriver.IsNull()) @@ -426,13 +425,13 @@ Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion( { if (refUserInfo(i).Search(MODIFICATION_COUNTER) != -1) { - try + TCollection_AsciiString aToken = refUserInfo(i).Token(" ", 2); + if (aToken.IsIntegerValue()) { - OCC_CATCH_SIGNALS theVersion = refUserInfo(i).Token(" ", 2).IntegerValue(); + theVersion = aToken.IntegerValue(); } - catch (Standard_Failure const&) + else { - // std::cout << "warning: could not read the version in " << aFileName << std::endl; TCollection_ExtendedString aMsg("Warning: "); aMsg = aMsg.Cat("could not read the version in ").Cat(aFileName).Cat("\0"); if (!theMsgDriver.IsNull()) diff --git a/src/Draw/TKXSDRAWSTL/XSDRAWSTL/XSDRAWSTL.cxx b/src/Draw/TKXSDRAWSTL/XSDRAWSTL/XSDRAWSTL.cxx index aa4d4b3f98..4632aba138 100644 --- a/src/Draw/TKXSDRAWSTL/XSDRAWSTL/XSDRAWSTL.cxx +++ b/src/Draw/TKXSDRAWSTL/XSDRAWSTL/XSDRAWSTL.cxx @@ -820,14 +820,13 @@ static Standard_Integer meshcolors(Draw_Interpretor& theDI, aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType); Standard_Real aScaleValue; - try + if (aDelta > Precision::Confusion()) { - OCC_CATCH_SIGNALS - aScaleValue = (aCoords.Value(1) - (Standard_Real)aMinX) / aDelta; + aScaleValue = (aCoords.Value(1) - aMinX) / aDelta; } - catch (Standard_Failure const&) + else { - aScaleValue = 0; + aScaleValue = 0.0; } aScaleMap.Bind(anIter.Key(), aScaleValue); -- 2.39.5