1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
7class FileError(Exception):
8 def __init__(self, *args, **kwargs):
9 Exception.__init__(self, *args, **kwargs)
10 self.context = {}
12 def set_context(self, k, v):
13 self.context[k] = v
15 def __str__(self):
16 s = Exception.__str__(self)
17 if not self.context:
18 return s
20 lines = []
21 for k in sorted(self.context.keys()):
22 lines.append('%s: %s\n' % (k, self.context[k]))
24 return '%s\n%s' % (s, '\n'.join(lines))
27class FileLoadError(FileError):
28 '''
29 Raised when a problem occurred while loading of a file.
30 '''
33class FileSaveError(FileError):
34 '''
35 Raised when a problem occurred while saving of a file.
36 '''