Python_2_Examples_and_Notes/spse_excercises/exc_mod1_p9_user_defined_ex...

14 lines
290 B
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Derive from Exception class (inheritance)
class MyError(Exception):
def __init__(self, value):
self.value = "...oooops!"
try:
raise(MyError(3*2))
except MyError as error:
print('User defined exception says: ',error.value)