🔥 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

Free 51 Websites for Learning Education and Courses

🛑 లక్à°·à°²ు à°–à°°్à°šుà°ªెà°Ÿ్à°Ÿి à°•ాà°²ేà°œీà°²్à°²ో à°¨ేà°°్à°šుà°•ోà°²ేà°¨ి à°µిà°·à°¯ాలను, à°«్à°°ీà°—ా à°¨ేà°°్à°ªింà°šే 51 à°…à°¦్à°­ుతమైà°¨ à°µెà°¬్‌à°¸ైà°Ÿ్à°²ు ఇవే! 🛑 à°Žà°¡్à°¯ుà°•ేà°·à°¨్ and à°•ోà°°్à°¸ుà°²ు: Co...