0% found this document useful (0 votes)
7 views2 pages

Exception PGM

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Exception PGM

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

try:

print(x)

except:

print("An exception occurred")

#Raise an error and stop the program if x is lower than 0:

#x = -1

#if x < 0:

# raise Exception("Sorry, no numbers below zero")

#x = "hello"

#if not type(x) is int:

#raise TypeError("Only integers are allowed")

The try block lets you test a block of code for errors.

The except block lets you handle the error.

The else block lets you execute code when there is no error.

The finally block lets you execute code, regardless of the result of the
try- and except blocks.

#try:

# print(x)
#except NameError:

# print("Variable x is not defined")

#except:

# print("Something else went wrong")

#try:

# print("Hello")

#except:

print("Something went wrong")

else:

print("Nothing went wrong")

try:

print(x)

except:

print("Something went wrong")

finally:

print("The 'try except' is finished")

You might also like