Raise value error : raise « Statement « Python Tutorial






import sys

dict = {}
dict[ValueError] = "Enter a valid value"
dict[IOError] = "An error occurred in the IO system"
try :
    raise ValueError
except :
    if dict.has_key(sys.exc_type) :
        print dict[sys.exc_type]








3.15.raise
3.15.1.raise Statement: raise [SomeException [, args [, traceback]]]
3.15.2.Raise value error
3.15.3.Raise error from function
3.15.4.raise ZeroDivisionError
3.15.5.raise exception-type