๐Ÿ”ฅ Welcome to my blog! Latest updates available now. Visit daily! ๐Ÿ”ฅ ๐Ÿ”ฅ Click Here for Latest Updates – Visit My Blog ๐Ÿ”ฅ
๐Ÿ”ฅ Latest Updates ๐Ÿ“Š GP Grade Finder ๐Ÿ“ข Government Services Info ๐Ÿ†• New Schemes Updates

Control Flow in try–except Python

 try:

    stmt-1

    stmt-2

    stmt-3

except XXX:

    stmt-4

stmt-5

Case–1:

If there is no exception

1, 2, 3, 5 → Normal Termination

Case–2:

If an exception is raised at stmt-2 and the corresponding except block is matched

1, 4, 5 → Normal Termination

Case–3:

If an exception is raised at stmt-2 and the corresponding except block is not matched

1 → Abnormal Termination

Case–4:

If an exception is raised at stmt-4 or at stmt-5, then it is always abnormal termination.


✅Conclusions:

๐Ÿ‘‰Within the try block, if an exception is raised anywhere, then the rest of the try block will not be executed, even though we handled that exception.


๐Ÿ‘‰Hence, we have to take only risky code inside the try block, and the length of the try block should be as small as possible.


๐Ÿ‘‰In addition to the try block, there may be a chance of raising exceptions inside except and finally blocks also.


๐Ÿ‘‰If any statement which is not part of the try block raises an exception, then it is always abnormal termination.

No comments:

Post a Comment

Thank you Very Much.For Given Comment

Quatation of the Day 22-03-2026