1 | # |
---|
2 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
3 | # Copyright 2010-2012 Chris Johns (chrisj@rtems.org) |
---|
4 | # All rights reserved. |
---|
5 | # |
---|
6 | # This file is part of the RTEMS Tools package in 'rtems-tools'. |
---|
7 | # |
---|
8 | # Permission to use, copy, modify, and/or distribute this software for any |
---|
9 | # purpose with or without fee is hereby granted, provided that the above |
---|
10 | # copyright notice and this permission notice appear in all copies. |
---|
11 | # |
---|
12 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
---|
13 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
---|
14 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
---|
15 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
---|
16 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
---|
17 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
---|
18 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
19 | |
---|
20 | # |
---|
21 | # Various errors we can raise. |
---|
22 | # |
---|
23 | |
---|
24 | class error(Exception): |
---|
25 | """Base class for Builder exceptions.""" |
---|
26 | def set_output(self, msg): |
---|
27 | self.msg = msg |
---|
28 | def __str__(self): |
---|
29 | return self.msg |
---|
30 | |
---|
31 | class general(error): |
---|
32 | """Raise for a general error.""" |
---|
33 | def __init__(self, what): |
---|
34 | self.set_output('error: ' + what) |
---|
35 | |
---|
36 | class internal(error): |
---|
37 | """Raise for an internal error.""" |
---|
38 | def __init__(self, what): |
---|
39 | self.set_output('internal error: ' + what) |
---|
40 | |
---|
41 | class exit(error): |
---|
42 | """Raise for to exit.""" |
---|
43 | def __init__(self): |
---|
44 | pass |
---|
45 | |
---|
46 | if __name__ == '__main__': |
---|
47 | try: |
---|
48 | raise general('a general error') |
---|
49 | except general, gerr: |
---|
50 | print 'caught:', gerr |
---|
51 | try: |
---|
52 | raise internal('an internal error') |
---|
53 | except internal, ierr: |
---|
54 | print 'caught:', ierr |
---|