File: exceptions.py

package info (click to toggle)
mnemosyne 1.2.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,804 kB
  • ctags: 497
  • sloc: python: 9,546; makefile: 41
file content (79 lines) | stat: -rw-r--r-- 1,834 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
##############################################################################
#
# Mnemosyne exceptions <Peter.Bienstman@UGent.be>
#
##############################################################################

import sys, traceback, string



##############################################################################
#
# Like traceback.print_exc(), but returns a string
#
##############################################################################

def traceback_string():

    type, value, tb = sys.exc_info()
    
    body = "\nTraceback (innermost last):\n"
    list = traceback.format_tb(tb, limit=None) + \
           traceback.format_exception_only(type, value)
    body = body + "%-20s %s" % (string.join(list[:-1], ""), list[-1],)
    
    return body



##############################################################################
#
# MnemosyneError
#
##############################################################################

class MnemosyneError(Exception):

    msg = '' # Will be filled in by the UI, to allow translation.
    
    def __init__(self, stack_trace=False, info=None):
        if stack_trace == True:
            self.info = traceback_string()
        else:
            self.info = info



##############################################################################
#
# Derived errors
#
##############################################################################

class ConfigError(MnemosyneError):
    pass

class PluginError(MnemosyneError):
    pass

class LoadError(MnemosyneError):
    pass

class LoadErrorCreateTmp(MnemosyneError):
    pass

class InvalidFormatError(MnemosyneError):
    pass

class SaveError(MnemosyneError):
    pass

class XMLError(MnemosyneError):
    pass

class EncodingError(MnemosyneError):
    pass

class MissingAnswerError(MnemosyneError):
    pass