🔥 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

Customized Exception Handling by using try-except in Python

👉It is highly recommended to handle

     exceptions.

👉The code which may raise an exception is

     called risky code, and we have to take      

     risky code inside the try block.

👉The corresponding handling code we

      have to take inside the except block.


Syntax:

try:

    Risky Code

except XXX:

    Handling code / Alternative Code


Example:without try-except:


1. print("stmt-1")

2. print(10/0)

3. print("stmt-3")


Output:

stmt-1

ZeroDivisionError: division by zero

Abnormal termination / Non-Graceful Termination


Example:with try-except:

1. print("stmt-1")

2. try:

3. print(10/0)

4. except ZeroDivisionError:

5. print(10/2)

6. print("stmt-3")


Output:

stmt-1

5.0

stmt-3

Normal termination / Graceful Termination

No comments:

Post a Comment

Thank you Very Much.For Given Comment

Birth & Death Registration Rules 2026

జనన, మరణాà°² నమోà°¦ు à°µిà°·à°¯ంà°²ో 2026 à°…à°•్à°Ÿోబర్ 1 à°¨ుంà°šి à°•ొà°¤్à°¤ à°¨ిà°¬ంధనలు అమల్à°²ోà°•ి à°°ాà°¨ుà°¨్à°¨ాà°¯ి. 🔹 21 à°°ోà°œుà°²్à°²ోà°ªు: à°¸ాà°§ాà°°à°£ à°°ిà°œిà°¸్à°Ÿ్à°°ేà°·à°¨్ 🔹 21 à°°ోà°œుà°² తర్à°µాà°¤...