Menu
Coddy logo textTech

Printing Exception Name

Lesson 7 of 16 in Coddy's Exception Handling in Python course.

We can print Exception name using class attribute.

try:
   #code which can cause exception
except [ExceptionName] as [object_name]:
   print(object_name.__class__)
challenge icon

Challenge

Easy

You will have list as input. Write a program to sum all elements in a list. If it encounters an exception during summation, it will raise an Exception. Otherwise, it will print summation. The Exception type is TypeError and text as "Exception name:Standard message

Try it yourself

def summation(my_list):
    #your code here

All lessons in Exception Handling in Python