Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class notes Python part 4

Rating
-
Sold
-
Pages
9
Uploaded on
22-12-2024
Written in
2024/2025

Conclution of python

Institution
Course

Content preview

Python Tutorial
Error Handling and Exception Handling in
Python:
Key Concepts
• Error handling is the process of recognizing and dealing with
errors during the execution of a program.
• Exception handling is a specific type of error handling that
allows a program to continue running even when an error
occurs.
• In Python, exceptions are errors that occur during the execution
of a program.
• When an exception occurs, the normal flow of the program is
interrupted and the interpreter looks for an exception handler to
handle the exception.
• If an exception handler is not found, the program will crash.
Types of Exceptions
• There are many different types of exceptions in Python,
including:
• SyntaxError: Raised when there is a syntax error in the
code.
• NameError: Raised when a variable is not defined.
• TypeError: Raised when an operation or function is applied
to an object of inappropriate type.
• ValueError: Raised when an operation or function receives
an argument of correct type but inappropriate value.

, • ZeroDivisionError: Raised when the second argument of a
division or modulo operation is zero.
• FileNotFoundError: Raised when a file or directory is
requested but doesn't exist.
Handling Exceptions
• To handle exceptions, you can use a try/except block. The code
that might raise an exception is placed in the try block, and the
code that handles the exception is placed in the except block.
• Here is an example:
try:
# code that might raise an exception
x=1/0
except ZeroDivisionError:
# code to handle the exception
print("Cannot divide by zero.")
• You can also use the finally block to specify code that should be
executed whether an exception is raised or not.
try:
# code that might raise an exception
x=1/0
except ZeroDivisionError:
# code to handle the exception
print("Cannot divide by zero.")
finally:
# code that will always run

Written for

Course

Document information

Uploaded on
December 22, 2024
Number of pages
9
Written in
2024/2025
Type
Class notes
Professor(s)
.
Contains
All classes

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
hp3329353

Also available in package deal

Get to know the seller

Seller avatar
hp3329353 Anna University
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
5
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions