w3ajay

tally tutorial point, ms word 2013, ms excel 2013, ms powerpoint 2010,ccc question with answer in hindi 2021, Tally Prime in hindi , tally prime,Python,in python,programming in python,python

Saturday, August 24, 2024

what is built in exception in exception handling in Python? class 12th

 What is built-in exception handling?


What is built in exception in exception handling in python class 12th

Built-in exceptions are predefined exceptions that are already defined in a programming language's standard library. They are automatically available for use by developers and are typically used to handle common error conditions.

built in exception are-

1)Name Error: Raised when trying to access a variable that has not been defined.

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    print(a)
Name Error: name 'a' is not defined

2)Zero Division Error: Raised when trying to divide by zero.
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    10/0
Zero Division Error: division by zero

3)TypeError: Raised when a variable is not of the expected type.
print('ram'/2)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    print('ram'/2)
TypeError: unsupported operand type(s) for /: 'str' and 'int'

4)IndexError: Raised when trying to access an index that is out of range.
a=[3,4,5,6,2]
print(a[11])
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    print(a[11])
IndexError: list index out of range

5)ValueError: Raised when a function receives an argument with an incorrect value.
a=int(input("Enter the number"))
Enter the numberram
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    a=int(input("Enter the number"))
ValueError: invalid literal for int() with base 10: 'ram'


6)ModuleNotFoundError: Raised when a module is not found
import math
import w3ajay
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    import w3ajay
ModuleNotFoundError: No module named 'w3ajay'


7)KeyboardInterrupt: Raised when the user presses Ctrl+C.
a=int(input("Enter the number"))
Enter the number
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    a=int(input("Enter the number"))
KeyboardInterrupt




No comments:

Post a Comment

for more information please share like comment and subscribe