Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
10 changes: 10 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234554.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:
10 changes: 10 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234555.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:
22 changes: 22 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234607.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:
# import module sys to get the type of exception
import sys
l = ['a', 0, 2]
for ele in l:
try:#This block might raise an exception while executing
print("The entry is", ele)
r = 1/int(ele)
break
except:#This block executes in case of an exception in "try"
print("Oops!", sys.exc_info()[0], "occurred.")
print()
print("The reciprocal of", ele, "is", r)
22 changes: 22 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234609.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:
# import module sys to get the type of exception
import sys
l = ['a', 0, 2]
for ele in l:
try:#This block might raise an exception while executing
print("The entry is", ele)
r = 1/int(ele)
break
except:#This block executes in case of an exception in "try"
print("Oops!", sys.exc_info()[0], "occurred.")
print()
print("The reciprocal of", ele, "is", r)
43 changes: 43 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234622.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:
# import module sys to get the type of exception
import sys
l = ['a', 0, 2]
for ele in l:
try:#This block might raise an exception while executing
print("The entry is", ele)
r = 1/int(ele)
break
except:#This block executes in case of an exception in "try"
print("Oops!", sys.exc_info()[0], "occurred.")
print()
print("The reciprocal of", ele, "is", r)
We get the output to this code as:
● In this program, we loop through the values of a list l.
● As previously mentioned, the portion that can cause an exception is placed
inside the try block.
● If no exception occurs, the except block is skipped and normal flow
continues(for last value).
● But if any exception occurs, it is caught by the except block (first and second
values).
● Here, we print the name of the exception using the exc_info() function
inside sys module.
● We can see that element “a” causes ValueError and 0 causes
ZeroDivisionError.
Every exception in Python inherits from the base Exception class. Thus we can
write the above code as:
9
The entry is a
Oops! <class 'ValueError'> occurred.
The entry is 0
Oops! <class 'ZeroDivisionError'> occured.
The entry is 2
The reciprocal of 2 is 0.5
44 changes: 44 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234630.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:
# import module sys to get the type of exception
import sys
l = ['a', 0, 2]
for ele in l:
try:#This block might raise an exception while executing
print("The entry is", ele)
r = 1/int(ele)
break
except:#This block executes in case of an exception in "try"
print("Oops!", sys.exc_info()[0], "occurred.")
print()
print("The reciprocal of", ele, "is", r)

We get the output to this code as:
● In this program, we loop through the values of a list l.
● As previously mentioned, the portion that can cause an exception is placed
inside the try block.
● If no exception occurs, the except block is skipped and normal flow
continues(for last value).
● But if any exception occurs, it is caught by the except block (first and second
values).
● Here, we print the name of the exception using the exc_info() function
inside sys module.
● We can see that element “a” causes ValueError and 0 causes
ZeroDivisionError.
Every exception in Python inherits from the base Exception class. Thus we can
write the above code as:
9
The entry is a
Oops! <class 'ValueError'> occurred.
The entry is 0
Oops! <class 'ZeroDivisionError'> occured.
The entry is 2
The reciprocal of 2 is 0.5
44 changes: 44 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234639.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:
# import module sys to get the type of exception
import sys
l = ['a', 0, 2]
for ele in l:
try:#This block might raise an exception while executing
print("The entry is", ele)
r = 1/int(ele)
break
except:#This block executes in case of an exception in "try"
print("Oops!", sys.exc_info()[0], "occurred.")
print()
print("The reciprocal of", ele, "is", r)

We get the output to this code as:
● In this program, we loop through the values of a list l.
● As previously mentioned, the portion that can cause an exception is placed
inside the try block.
● If no exception occurs, the except block is skipped and normal flow
continues(for last value).
● But if any exception occurs, it is caught by the except block (first and second
values).
● Here, we print the name of the exception using the exc_info() function
inside sys module.
● We can see that element “a” causes ValueError and 0 causes
ZeroDivisionError.
Every exception in Python inherits from the base Exception class. Thus we can
write the above code as:
9
The entry is a
Oops! <class 'ValueError'> occurred.
The entry is 0
Oops! <class 'ZeroDivisionError'> occured.
The entry is 2
The reciprocal of 2 is 0.5
45 changes: 45 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234642.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:

# import module sys to get the type of exception
import sys
l = ['a', 0, 2]
for ele in l:
try:#This block might raise an exception while executing
print("The entry is", ele)
r = 1/int(ele)
break
except:#This block executes in case of an exception in "try"
print("Oops!", sys.exc_info()[0], "occurred.")
print()
print("The reciprocal of", ele, "is", r)

We get the output to this code as:
● In this program, we loop through the values of a list l.
● As previously mentioned, the portion that can cause an exception is placed
inside the try block.
● If no exception occurs, the except block is skipped and normal flow
continues(for last value).
● But if any exception occurs, it is caught by the except block (first and second
values).
● Here, we print the name of the exception using the exc_info() function
inside sys module.
● We can see that element “a” causes ValueError and 0 causes
ZeroDivisionError.
Every exception in Python inherits from the base Exception class. Thus we can
write the above code as:
9
The entry is a
Oops! <class 'ValueError'> occurred.
The entry is 0
Oops! <class 'ZeroDivisionError'> occured.
The entry is 2
The reciprocal of 2 is 0.5
46 changes: 46 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234645.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:

# import module sys to get the type of exception
import sys
l = ['a', 0, 2]
for ele in l:
try:#This block might raise an exception while executing
print("The entry is", ele)
r = 1/int(ele)
break
except:#This block executes in case of an exception in "try"
print("Oops!", sys.exc_info()[0], "occurred.")
print()
print("The reciprocal of", ele, "is", r)

We get the output to this code as:

● In this program, we loop through the values of a list l.
● As previously mentioned, the portion that can cause an exception is placed
inside the try block.
● If no exception occurs, the except block is skipped and normal flow
continues(for last value).
● But if any exception occurs, it is caught by the except block (first and second
values).
● Here, we print the name of the exception using the exc_info() function
inside sys module.
● We can see that element “a” causes ValueError and 0 causes
ZeroDivisionError.
Every exception in Python inherits from the base Exception class. Thus we can
write the above code as:
9
The entry is a
Oops! <class 'ValueError'> occurred.
The entry is 0
Oops! <class 'ZeroDivisionError'> occured.
The entry is 2
The reciprocal of 2 is 0.5
47 changes: 47 additions & 0 deletions .history/Lesson 7 - Exception Handling/Catching_20221006234646.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Catching Exceptions
In Python, exceptions can be handled using try-except blocks.
● If the Python program contains suspicious code that may throw the
exception, we must place that code in the try block.
● The try block must be followed by the except statement, which contains a
block of code that will be executed in case there is some exception in the try
block.
● We can thus choose what operations to perform once we have caught the
exception.
● Here is a simple example:

# import module sys to get the type of exception
import sys
l = ['a', 0, 2]
for ele in l:
try:#This block might raise an exception while executing
print("The entry is", ele)
r = 1/int(ele)
break
except:#This block executes in case of an exception in "try"
print("Oops!", sys.exc_info()[0], "occurred.")
print()
print("The reciprocal of", ele, "is", r)

We get the output to this code as:


● In this program, we loop through the values of a list l.
● As previously mentioned, the portion that can cause an exception is placed
inside the try block.
● If no exception occurs, the except block is skipped and normal flow
continues(for last value).
● But if any exception occurs, it is caught by the except block (first and second
values).
● Here, we print the name of the exception using the exc_info() function
inside sys module.
● We can see that element “a” causes ValueError and 0 causes
ZeroDivisionError.
Every exception in Python inherits from the base Exception class. Thus we can
write the above code as:
9
The entry is a
Oops! <class 'ValueError'> occurred.
The entry is 0
Oops! <class 'ZeroDivisionError'> occured.
The entry is 2
The reciprocal of 2 is 0.5
Loading