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

Friday, August 23, 2024

Exception Handling in Python Class 12 Computer Science

 Computer Science Python Class 12 Chapter 5 Python Exception Handling








What is exceptional handling in Python?

These are the syntax error that can be found during compilation of the program that means programming did not follow syntax. in case of syntax error , Program never run.Way of handling anomalous situations in a program-run, is known as Exception Handling.


What is exceptional in Python?

The error/bugs that is identified during execution of the program is called Exception. Exception are run time errors that causes termination of the program.

An exception is an event that occurs during the execution of a program, disrupting the normal flow of instructions. It's an error or an unusual condition that requires special handling to prevent the program from crashing or producing unexpected results.

when there is a Exception then there is a problem 

Problem 

The whole Program is terminated when an Exception is encountered 

Solution 

To Solve the Errors/Issue of Exception so that the Program is not terminated when it encounters an Exception we use the concept of "Exception handling" 

Types of Exception 

(i) Buil-in-Exception 
(ii) User-Defined-Exception 

(i) Buil-in-Exception 

        These are the Exception that are defined already .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.

(ii) User-Defined-Exception 

The Exception that are handled by the user is called user defined Exception . A user-defined exception is a custom exception created by a developer to handle specific error conditions that are not covered by built-in exceptions. It allows developers to define their own exceptions and handle them accordingly.

Buil-in-Exception are----


1. BaseException: The base class for all exceptions.
2. SystemExit: Raised when the program tries to exit using sys.exit().
3. KeyboardInterrupt: Raised when the user presses Ctrl+C.
4. Exception: The base class for all built-in exceptions.
5. StopIteration: Raised when the next value is not available in an iterator.
6. ArithmeticError: The base class for arithmetic-related exceptions.
    - FloatingPointError: Raised when a floating-point operation fails.
    - OverflowError: Raised when a calculation exceeds the maximum limit.
    - ZeroDivisionError: Raised when trying to divide by zero.
7. AssertionError: Raised when an assertion fails.
8. AttributeError: Raised when trying to access an attribute that does not exist.
9. BufferError: Raised when a buffer-related operation fails.
10. EOFError: Raised when the end of a file is reached unexpectedly.
11. ImportError: Raised when an import operation fails.
    - ModuleNotFoundError: Raised when a module is not found.
12. LookupError: The base class for lookup-related exceptions.
    - IndexError: Raised when trying to access an index that is out of range.
    - KeyError: Raised when trying to access a key that does not exist in a dictionary.
13. MemoryError: Raised when the program runs out of memory.
14. NameError: Raised when trying to access a variable that has not been defined.
    - UnboundLocalError: Raised when trying to access a local variable that has not been assigned.
15. OSError: The base class for OS-related exceptions.
    - ChildProcessError: Raised when a child process operation fails.
    - FileExistsError: Raised when trying to create a file that already exists.
    - FileNotFoundError: Raised when trying to access a file that does not exist.
    - InterruptedError: Raised when a system call is interrupted.
    - IsADirectoryError: Raised when trying to access a directory as a file.
    - NotADirectoryError: Raised when trying to access a file as a directory.
    - PermissionError: Raised when trying to perform an operation without permission.
    - ProcessLookupError: Raised when trying to access a process that does not exist.
16. ReferenceError: Raised when a weak reference is no longer valid.
17. RuntimeError: Raised when an error occurs during the execution of a program.
    - NotImplementedError: Raised when a method is not implemented.
18. SyntaxError: Raised when there is a syntax error in the code.
    - IndentationError: Raised when there is an indentation error in the code.
    - TabError: Raised when there is an inconsistent use of tabs and spaces.
19. SystemError: Raised when a system-related error occurs.
20. TypeError: Raised when a variable is not of the expected type.
21. ValueError: Raised when a function receives an argument with an incorrect value.
22. Warning: The base class for warning-related exceptions.
23.IOError: Occurs when there is an input/output error, such as trying to read a file that does not exist.

No comments:

Post a Comment

for more information please share like comment and subscribe