perlquestion
pfaut
<p>I'm writing an XS interface to a library and could use some advice on how to return error information.</p>
<p>The routines in the library return 0 if the call succeeded or a status value if there was an error. The library contains a routine to convert the status codes into strings that can be displayed for a user.</p>
<p>My interface routines mostly collect the information into a hash and return a reference to the caller. In case of error I'm returning an empty list. I would like to make the error information available to the caller because it could be very meaningful in certain cases (e.g., 'end of file' vs. other I/O error conditions).</p>
<p>I can't really return the status in <c>$!</c> since it isn't an errno value. I can return the error text in <c>$@</c> but then the programmer would have to parse the error text rather than acting on an error code.</p>
<p>I'm contemplating replacing my simple handle object with a structure that can contain the handle and the last status returned by a library call using that handle. I could then add an XS routine to return that status to the calling program. The user could call the status fetch routine if one of the other calls returned undef. But this still doesn't help the <c>open</c> call that creates the handle (if the handle doesn't exist yet, I can't use it to hold status).</p>
<p>Any ideas?</p>
<div class="pmsig"><div class="pmsig-217641">
<center><table><tr><td><font size="-1">90% of every Perl application is already written. [id://246498|⇒]</font></td></tr><tr><td align="right"><font size="-1"><i>[dragonchild]</i></font></td></tr></table></center>
</div></div>