Multiple 'endings' to a function - return an object, return a string, raise an exception?
<p>This one's a structure design problem, I guess. Back for some advice.</p>

<p>To start: I'm writing a module. Hence the effort of making it as usable to potential developers as possible.</p>

<p>Inside an object (let's call it <code>Swoosh</code>) I have a method which, when called, may result in either success (a new object is returned -- for insight: it's an <code>httplib.HTTPResponse</code>) or failure (surprising, isn't it?).</p>

<p>I'm having trouble deciding how to handle failures. There are two main cases here:</p>

<ol>
<li>user supplied data that was incorrect</li>
<li>data was okay, but user interaction will be needed () - I need to pass back to the user a string that he or she will need to use in some way.</li>
</ol>

<p>In (1) I decided to <code>raise ValueError()</code> with an appropriate description.
In (2), as I need to actually pass a <code>str</code> back to the user.. I'm not sure about whether it would be best to just <code>return</code> a string and leave it to the user to check what the function returned (<code>httplib.HTTPResponse</code> or <code>str</code>) or <code>raise</code> a custom exception? Is passing data through raising exceptions a good idea? I don't think I've seen this done anywhere, but on the other hand - I haven't seen much.</p>

<p>What would you, as a developer, expect from an object/function like this?</p>

<p>Or perhaps you find the whole design ridiculous - let me know, I'll happily learn.</p>
