πŸ”₯ 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

Quatation of the Day 22-03-2026