File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -303,3 +303,23 @@ And this is how extend() works:
303
303
>>> list1
304
304
[1, 2, 3, 4, 5, 6, 7, 8]
305
305
```
306
+
307
+ #### 16. Explain ` try ` , ` raise ` and ` finally ` .
308
+
309
+ These are the keywords we use with __ exception-handling__ .<br >
310
+ - We put risky code under a ` try ` block
311
+ - Use the ` raise ` statement to __ explicitly raise an error__
312
+ - Use the ` finally ` block to put code that __ we want to execute anyway__ .
313
+
314
+ ```
315
+ >>> try:
316
+ print(1/0)
317
+ except ValueError:
318
+ print("This is a value error")
319
+ finally:
320
+ print("This will print no matter what.")
321
+
322
+ # OUTPUT:
323
+ # This will print no matter what.
324
+ ```
325
+ Because in the try block we got a __ DivisionByZeroException__ and not ValueError, so that is not caught and ` finally ` block is executed.
You can’t perform that action at this time.
0 commit comments