[go: up one dir, main page]

0% found this document useful (0 votes)
9 views6 pages

Exception Handling P3 - Notes Lyst3039

The document discusses exception handling in Python, illustrating how exceptions propagate through multiple method calls. It explains that if an exception is not handled in the method where it occurs, it will trace back to the calling method, potentially leading to abrupt termination of the program. Examples demonstrate how placing 'except' blocks in different methods affects the execution flow and exception handling.

Uploaded by

vennelavpf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Exception Handling P3 - Notes Lyst3039

The document discusses exception handling in Python, illustrating how exceptions propagate through multiple method calls. It explains that if an exception is not handled in the method where it occurs, it will trace back to the calling method, potentially leading to abrupt termination of the program. Examples demonstrate how placing 'except' blocks in different methods affects the execution flow and exception handling.

Uploaded by

vennelavpf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Today’s Agenda

 Exception handling contd

Exception handling contd


Let us see how exception handling mechanism works when multiple
method calls are involved through the following example

1 Python fundamental| Rooman Technologies


Output:

Stack

ZeroDivisionError fun2()
num 100
Traceback

den 0

res 100/0
ZeroDivisionError

fun1()

ZeroDivisionError

main()

Abrupt termination

2 Python fundamental| Rooman Technologies


If except block is not in the method where exception is generated
then it traces back to the method who called for it and checks in
that method. If anywhere it is not present then the program is
abruptly terminated.

Let us try to handle this exception

Output:

3 Python fundamental| Rooman Technologies


Stack

ZeroDivisionError fun2()
num 100

den 0

Execution completes res 100/0

fun1()

main()

Let us see what happens when the except block is in fun1()

4 Python fundamental| Rooman Technologies


Output:

We can see that exception is been handled, but fun2() did not finish
it’s execution as the control came to fun1() along with exception
object.

Let us also try placing the except block in main()

5 Python fundamental| Rooman Technologies


Output:

As we see exception is handled but fun1() and fun2() did not finish
their execution.

6 Python fundamental| Rooman Technologies

You might also like