File: wb_exceptions.py

package info (click to toggle)
svn-workbench 1.5.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,400 kB
  • ctags: 1,585
  • sloc: python: 12,163; sh: 74; makefile: 46; ansic: 9
file content (51 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (4)
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
'''
 ====================================================================
 Copyright (c) 2003-2006 Barry A Scott.  All rights reserved.

 This software is licensed as described in the file LICENSE.txt,
 which you should have received as part of this distribution.

 ====================================================================

    wb_exceptions.py

'''
class WorkBenchError(Exception):
    def __init__( self, msg ):
        Exception.__init__( self, msg )

class InternalError(WorkBenchError):
    def __init__( self, msg ):
        WorkBenchError.__init__( self, msg )

#
#    Helper class to cut down code bloat.
#
#    in __init__ add:
#        self.try_wrapper = wb_exceptions.TryWrapperFactory( log )
#
#    where binding an EVT code as:
#
#        wxPython.wx.EVT_SIZE( self, self.try_wrapper( self.OnSize ) )
#
class TryWrapperFactory:
    def __init__( self, log ):
        self.log = log

    def __call__( self, function ):
        return TryWrapper( self.log, function )

class TryWrapper:
    def __init__( self, log, function ):
        self.log = log
        self.function = function

    def __call__( self, *params, **keywords ):
        try:
            result = self.function( *params, **keywords )
            return result
        except Exception:
            self.log.exception( 'TryWrapper<%s.%s>\n' %
                (self.function.__module__, self.function.__name__ ) )

            return None