You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lessons/l24.rst
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,6 +128,31 @@
128
128
raise RuntimeError("Something bad happened") from exception
129
129
RuntimeError: Something bad happened
130
130
131
+
به عنوان یک نمونه کاربرد، از این روش میتوان برای ایجاد یک Wrapper برای چندین Exception بهره برد. در این حالت کد سطح بالاتر تنها نیاز است یک نوع Exception را handle نماید:
132
+
133
+
.. code-block:: python
134
+
:linenos:
135
+
136
+
defsum_int(a, b):
137
+
try:
138
+
return a + b
139
+
exceptTypeErroras type_err:
140
+
raiseRuntimeError(f'Something bad happened \n => {str(type_err)}') from type_err
0 commit comments