Why you specify type and name of the exception in your custom exceptions,
but not in python built in exceptions?

except IOError:
print "no file by the name ccy_rates*.txt"

except MyError, e:
print e.msg

Recommended Answers

All 2 Replies

Why you specify type and name of the exception in your custom exceptions,
but not in python built in exceptions?

except IOError:
        print "no file by the name ccy_rates*.txt"
        
    except MyError, e:
                print e.msg

When you are creating custom exception, why you don't import exceptions?

import exceptions

You mean something like that:

try:
    fin = open("missing.txt", 'r')
# optional error value what_error
except IOError, what_error:
    print what_error

"""
result -->
[Errno 2] No such file or directory: 'missing.txt'
"""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.