Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I'm writing an XS interface to a library and could use some advice on how to return error information.

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.

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).

I can't really return the status in $! since it isn't an errno value. I can return the error text in $@ but then the programmer would have to parse the error text rather than acting on an error code.

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 open call that creates the handle (if the handle doesn't exist yet, I can't use it to hold status).

Any ideas?

90% of every Perl application is already written.
dragonchild

In reply to Returning external library status codes from an XS routine by pfaut

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (9)
    As of 2014-12-20 04:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (95 votes), past polls