You should read the python documentation on Exceptions.
But generally speaking yes, you can define your own exception types just like any other class by extending Exception
or any other appropriate error type (in this case I'd probably use IOError
)
Example:
class NoDatabaseError(IOError):
pass
And then in the code above the database open:
try:
open_database(database)
except NoDatabaseError as e:
print('Could Not Open The Database: '+str(e))
except Exception as e:
print('Something Unexpected Went On:'+str(e))
If that's not what you're asking, you should clarify your question.