@@ -85,39 +85,56 @@ def _decode(cdata):
8585class JackError (Exception ):
8686 """Exception for all kinds of JACK-related errors."""
8787
88- def __init__ (self , msg , errno = None ):
89- """Initialize new exception instance.
9088
91- Parameters
89+ class JackErrorCode (JackError ):
90+
91+ def __init__ (self , message , code ):
92+ """Exception for JACK errors with an error code.
93+
94+ Subclass of `JackError`.
95+
96+ The following attributes are available:
97+
98+ Attributes
9299 ----------
93- errno : int, optional
94- The error code returned by the JACK library function, which
95- resulted in this exception being raised. Defaults to `None`.
96- This will be accessible via the `errno` attribute of the
97- exception instance .
100+ message
101+ Error message.
102+ code
103+ The error code returned by the JACK library function which
104+ resulted in this exception being raised .
98105
99106 """
100- super ().__init__ (msg )
101- self .errno = errno
107+ self .message = message
108+ self .code = code
109+
110+ def __str__ (self ):
111+ return '{} ({})' .format (self .message , self .code )
102112
103113
104114class JackOpenError (JackError ):
105- """Exception raised when no connection to the JACK server could opened."""
106115
107- def __init__ (self , msg , status ):
108- """Initialize new exception instance .
116+ def __init__ (self , name , status ):
117+ """Exception raised for errors while creating a JACK client .
109118
110- Parameters
119+ Subclass of `JackError`.
120+
121+ The following attributes are available:
122+
123+ Attributes
111124 ----------
112- status : :class:`Status`
125+ name
126+ Requested client name.
127+ status
113128 A :class:`Status` instance representing the status information
114- received by the `jack_client_open` JACK library call. This will be
115- accessible via the `status` attribute of the exception instance.
129+ received by the ``jack_client_open()`` JACK library call.
116130
117131 """
118- super (). __init__ ( msg )
132+ self . name = name
119133 self .status = status
120134
135+ def __str__ (self ):
136+ return 'Error initializing "{}": {}' .format (self .name , self .status )
137+
121138
122139class Client (object ):
123140 """A client that can connect to the JACK audio server."""
@@ -182,8 +199,7 @@ def __init__(self, name, use_exact_name=False, no_start_server=False,
182199 * optargs )
183200 self ._status = Status (status [0 ])
184201 if not self ._ptr :
185- raise JackOpenError ('Error initializing "{0}": {1}'
186- .format (name , self .status ), status = self .status )
202+ raise JackOpenError (name , self ._status )
187203
188204 self ._inports = Ports (self , _AUDIO , _lib .JackPortIsInput )
189205 self ._outports = Ports (self , _AUDIO , _lib .JackPortIsOutput )
@@ -465,9 +481,9 @@ def connect(self, source, destination):
465481 err = _lib .jack_connect (self ._ptr , source .encode (),
466482 destination .encode ())
467483 if err == _errno .EEXIST :
468- raise JackError ('Connection {0!r} -> {1!r} '
469- 'already exists' .format (source , destination ),
470- errno = err )
484+ raise JackErrorCode ('Connection {0!r} -> {1!r} '
485+ 'already exists' .format (source , destination ),
486+ err )
471487 _check (err ,
472488 'Error connecting {0!r} -> {1!r}' .format (source , destination ))
473489
@@ -2995,4 +3011,4 @@ def callback_wrapper(msg):
29953011def _check (error_code , msg ):
29963012 """Check error code and raise JackError if non-zero."""
29973013 if error_code :
2998- raise JackError ( '{0} ({1})' . format ( msg , error_code ), errno = error_code )
3014+ raise JackErrorCode ( msg , error_code )
0 commit comments