Skip to content

Commit d223193

Browse files
authored
Added new "Example Code Example" section and put it after Exceptions.
I thought this order made more sense than before, will discuss with Helge Signed-off-by: BartyBoi1128 <[email protected]>
1 parent b5bcf0d commit d223193

File tree

1 file changed

+6
-4
lines changed
  • docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-390

1 file changed

+6
-4
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-390/REAME.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,15 @@ exception_example()
9090

9191
The following two exceptions, highlighted in [SEI Cert's Oracle Coding Standard for Java](https://wiki.sei.cmu.edu/confluence/display/java/SEI+CERT+Oracle+Coding+Standard+for+Java), are important to understand when to attempt to handle exceptions at the right level in the stack in Python also.
9292

93-
We wrote a code example in Python in order to assist in the understanding of these exceptions [SEI CERT ERR00-J 2025](https://wiki.sei.cmu.edu/confluence/display/java/ERR00-J.+Do+not+suppress+or+ignore+checked+exceptions).
94-
9593
* __ERR00-J-EX0:__ You may suppress exceptions during the release of non-reusable resources, such as closing files, network sockets, or shutting down threads, if they don't affect future program behavior.
9694
* __ERR00-J-EX1:__ Allow higher-level code to catch and attempt recovery from exceptions. If recovery is not possible, log the exception, add information if needed, and rethrow it.
9795

96+
## Example Code Example
97+
98+
If recovery from an exception remains impossible, it is often best practice to wrap the checked exception in an unchecked exception and rethrow it. This approach allows the application to fail gracefully or log the error for future debugging, rather than crashing unexpectedly.
99+
100+
`example01.py` assist in the understanding of Java's SEI Cert exceptions [SEI CERT ERR00-J 2025](https://wiki.sei.cmu.edu/confluence/display/java/ERR00-J.+Do+not+suppress+or+ignore+checked+exceptions)..
101+
98102
*[example01.py](example01.py):*
99103

100104
```py
@@ -120,8 +124,6 @@ def exception_example():
120124
exception_example()
121125
```
122126

123-
If recovery remains impossible, wrap the checked exception in an unchecked exception and rethrow it.
124-
125127
## Automated Detection
126128

127129
|Tool|Version|Checker|Description|

0 commit comments

Comments
 (0)