Coding - Reducing relying on exceptions#676
Conversation
Updated PCDM_ReadWriter_1.cxx to avoid exceptions in reading reference counter and version. Updated XSDRAWSTL to avoid null division checks.
There was a problem hiding this comment.
Pull Request Overview
This PR aims to improve error handling by replacing exception-based control flow with explicit condition checks. The changes reduce reliance on exceptions for predictable error conditions, which can improve performance and code clarity.
- 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
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ApplicationFramework/TKCDF/PCDM/PCDM_ReadWriter_1.cxx | Replaced exception handling with explicit integer validation checks for reading reference counter and document version |
| src/Draw/TKXSDRAWSTL/XSDRAWSTL/XSDRAWSTL.cxx | Added division-by-zero protection using precision comparison instead of exception handling |
| if (aToken.IsIntegerValue()) | ||
| { | ||
| OCC_CATCH_SIGNALS theReferencesCounter = refUserInfo(i).Token(" ", 2).IntegerValue(); | ||
| theReferencesCounter = aToken.IntegerValue(); |
There was a problem hiding this comment.
The variable name 'aToken' follows OCCT naming conventions correctly, but consider using a more descriptive name like 'aCounterToken' to better express its purpose in this context.
| if (aToken.IsIntegerValue()) | ||
| { | ||
| OCC_CATCH_SIGNALS theVersion = refUserInfo(i).Token(" ", 2).IntegerValue(); | ||
| theVersion = aToken.IntegerValue(); |
There was a problem hiding this comment.
Similar to the reference counter case, consider using a more descriptive variable name like 'aVersionToken' instead of the generic 'aToken' for better code clarity.
- 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
- 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
Updated PCDM_ReadWriter_1.cxx to avoid exceptions in reading reference counter and version.
Updated XSDRAWSTL to avoid null division checks.