]> OCCT Git - occt.git/commitdiff
Coding - Reducing relying on exceptions (#676)
authorPasukhin Dmitry <dpasukhi@opencascade.com>
Sat, 16 Aug 2025 12:55:33 +0000 (13:55 +0100)
committerGitHub <noreply@github.com>
Sat, 16 Aug 2025 12:55:33 +0000 (13:55 +0100)
- 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

src/ApplicationFramework/TKCDF/PCDM/PCDM_ReadWriter_1.cxx
src/Draw/TKXSDRAWSTL/XSDRAWSTL/XSDRAWSTL.cxx

index cff2929f015c64416ac5c741cc245a3e20d887f3..2dbef896a314c25f728e123c84e715c0f9bc6168 100644 (file)
@@ -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())
index aa4d4b3f9823894caed109331544c485b506a992..4632aba138458236a11e65f9082bde6f9ea89266 100644 (file)
@@ -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);