[bf13d27] | 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 | |
---|
[f88fcf3] | 20 | from __future__ import print_function |
---|
| 21 | |
---|
[bf13d27] | 22 | # |
---|
| 23 | # Various errors we can raise. |
---|
| 24 | # |
---|
| 25 | |
---|
| 26 | class error(Exception): |
---|
| 27 | """Base class for Builder exceptions.""" |
---|
| 28 | def set_output(self, msg): |
---|
| 29 | self.msg = msg |
---|
| 30 | def __str__(self): |
---|
| 31 | return self.msg |
---|
| 32 | |
---|
| 33 | class general(error): |
---|
| 34 | """Raise for a general error.""" |
---|
| 35 | def __init__(self, what): |
---|
| 36 | self.set_output('error: ' + what) |
---|
| 37 | |
---|
| 38 | class internal(error): |
---|
| 39 | """Raise for an internal error.""" |
---|
| 40 | def __init__(self, what): |
---|
| 41 | self.set_output('internal error: ' + what) |
---|
| 42 | |
---|
| 43 | class exit(error): |
---|
| 44 | """Raise for to exit.""" |
---|
| 45 | def __init__(self): |
---|
| 46 | pass |
---|
| 47 | |
---|
| 48 | if __name__ == '__main__': |
---|
| 49 | try: |
---|
| 50 | raise general('a general error') |
---|
[f88fcf3] | 51 | except general as gerr: |
---|
| 52 | print('caught:', gerr) |
---|
[bf13d27] | 53 | try: |
---|
| 54 | raise internal('an internal error') |
---|
[f88fcf3] | 55 | except internal as ierr: |
---|
| 56 | print('caught:', ierr) |
---|