1 | # |
---|
2 | # $Id$ |
---|
3 | # |
---|
4 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
5 | # Copyright 2010 Chris Johns (chrisj@rtems.org) |
---|
6 | # All rights reserved. |
---|
7 | # |
---|
8 | # This file is part of the RTEMS Tools package in 'rtems-tools'. |
---|
9 | # |
---|
10 | # RTEMS Tools is free software: you can redistribute it and/or modify |
---|
11 | # it under the terms of the GNU General Public License as published by |
---|
12 | # the Free Software Foundation, either version 3 of the License, or |
---|
13 | # (at your option) any later version. |
---|
14 | # |
---|
15 | # RTEMS Tools is distributed in the hope that it will be useful, |
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | # GNU General Public License for more details. |
---|
19 | # |
---|
20 | # You should have received a copy of the GNU General Public License |
---|
21 | # along with RTEMS Tools. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | # |
---|
23 | |
---|
24 | # |
---|
25 | # Various errors we can raise. |
---|
26 | # |
---|
27 | |
---|
28 | class error(Exception): |
---|
29 | """Base class for Builder exceptions.""" |
---|
30 | def set_output(self, msg): |
---|
31 | self.msg = msg |
---|
32 | def __str__(self): |
---|
33 | return self.msg |
---|
34 | |
---|
35 | class general(error): |
---|
36 | """Raise for a general error.""" |
---|
37 | def __init__(self, what): |
---|
38 | self.set_output('error: ' + what) |
---|
39 | |
---|
40 | class internal(error): |
---|
41 | """Raise for an internal error.""" |
---|
42 | def __init__(self, what): |
---|
43 | self.set_output('internal error: ' + what) |
---|
44 | |
---|
45 | if __name__ == '__main__': |
---|
46 | try: |
---|
47 | raise general('a general error') |
---|
48 | except general, gerr: |
---|
49 | print 'caught:', gerr |
---|
50 | try: |
---|
51 | raise internal('an internal error') |
---|
52 | except internal, ierr: |
---|
53 | print 'caught:', ierr |
---|