🔥 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

Free 51 Websites for Learning Education and Courses

🛑 లక్షలు ఖర్చుపెట్టి కాలేజీల్లో నేర్చుకోలేని విషయాలను, ఫ్రీగా నేర్పించే 51 అద్భుతమైన వెబ్‌సైట్లు ఇవే! 🛑 ఎడ్యుకేషన్ and కోర్సులు: Co...