On Python 3 (only), the raise ... from ... syntax can be used as follows:
class DatabaseError(Exception):
pass
class FileDatabase:
def __init__(self, filename):
try:
self.file = open(filename)
except IOError as exc:
raise DatabaseError('failed to open') from exc
(see PEP 3134). This ticket is a feature request for an equivalent mechanism to be provided as e.g. future.utils.raise_from().