File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed
docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-390 Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -104,24 +104,30 @@ If recovery from an exception remains impossible, it is often best practice to w
104104``` py
105105# SPDX-FileCopyrightText: OpenSSF project contributors
106106# SPDX-License-Identifier: MIT
107- """ Compliant Code Example """
108- from time import sleep
107+ """ Code Example"""
109108
110109
111- def exception_example ():
112- """ Compliant Code Example catching a specific exception"""
113- while True :
114- sleep(1 )
115- try :
116- _ = 1 / 0
117- except ZeroDivisionError :
118- print (" How is it now?" )
110+ def slice_cake (cake : int , plates : int ) -> float :
111+ """ Calculates size of each slice per plate for a cake
112+ Args:
113+ cake (int) : Size of the cake
114+ guests (int): Amount of guests
115+ Returns:
116+ (float): Size of each slice
117+ """
118+
119+ try :
120+ return cake / plates
121+ except ZeroDivisionError as zero_division_error:
122+ raise ZeroDivisionError (
123+ " slice_cake:You got to give me plates"
124+ ) from zero_division_error
119125
120126
121127# ####################
122128# exploiting above code example
123129# ####################
124- exception_example( )
130+ slice_cake( cake = 100 , plates = 0 )
125131```
126132
127133## Automated Detection
You can’t perform that action at this time.
0 commit comments