Hi

Consider a 'send' method that sends a message to another system via a socket.  
This method will wait for a response before returning.  There are two possible 
error conditions:


1)      Timeout - i.e. no response received

2)      Illegal response received

I need to communicate these errors to the caller of send().  So far I have just 
raised a RuntimeError exception for both errors, and stated what happened like 
this:

raise RuntimeError("Message timeout")

That's fine if the caller just wants to print the error but not so good if the 
code needs to act differently according to which error condition occurred.

So, my question is, what's the pythonic way of doing this?  Should I subclass 
RuntimeError for each possible error condition?  E.g.:

               class MessageTimeoutError(RuntimeError): pass
               class IllegalResponseError(RuntimeError): pass

Best regards

David

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to