source: rtems-source-builder/source-builder/sb/error.py @ f88fcf3

4.11
Last change on this file since f88fcf3 was f88fcf3, checked in by Chris Johns <chrisj@…>, on Mar 7, 2016 at 12:56:02 AM

sb: Update code base to support Python3 and Python2.

Fix Windows support to allow MSYS2 Python to be used.

Updates #2619.

  • Property mode set to 100644
File size: 1.7 KB
Line 
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
20from __future__ import print_function
21
22#
23# Various errors we can raise.
24#
25
26class 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
33class general(error):
34    """Raise for a general error."""
35    def __init__(self, what):
36        self.set_output('error: ' + what)
37
38class internal(error):
39    """Raise for an internal error."""
40    def __init__(self, what):
41        self.set_output('internal error: ' + what)
42
43class exit(error):
44    """Raise for to exit."""
45    def __init__(self):
46        pass
47
48if __name__ == '__main__':
49    try:
50        raise general('a general error')
51    except general as gerr:
52        print('caught:', gerr)
53    try:
54        raise internal('an internal error')
55    except internal as ierr:
56        print('caught:', ierr)
Note: See TracBrowser for help on using the repository browser.