Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6058461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:36:07+00:00 2026-05-23T08:36:07+00:00

xsubpp can generate exception handling code for c/c++ files converted from .xs files. It

  • 0

xsubpp can generate exception handling code for c/c++ files converted from .xs files. It generates the following piece of code for me

TRY {
    char *  CLASS = (char *)SvPV_nolen(ST(0));
    Example *   RETVAL;

    RETVAL = new Example();
    ST(0) = sv_newmortal();
    sv_setref_pv( ST(0), CLASS, (void*)RETVAL );

}
BEGHANDLERS
CATCHALL
    sprintf(errbuf, "%s: %s\tpropagated", Xname, Xreason);
ENDHANDLERS

But when compiling the generated code, I’m getting compilation errors as TRY, BEGHANDLERS, CATCHALL, ENDHANDLERS were not defined anywhere in perl header files. I’ve modified my code to define the above mentioned tokens like this.

#define TRY try
#define BEGHANDLERS
#define CATCHALL catch (...) {
#define ENDHANDLERS }

But I’m not able to give meaningful definitions to Xname and Xreason. Are the above definitions correct ? How do we handle the above mentioned keywords

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:36:07+00:00Added an answer on May 23, 2026 at 8:36 am

    This falls into the “well don’t do that then” category. (The canonical answer to “Doctor, it hurts when I do X”). Look at the generated code:

    CATCHALL
        sprintf(errbuf, "%s: %s\tpropagated", Xname, Xreason);
    ENDHANDLERS
    

    This isn’t propagating the exception. It is printing a message and then utterly ignoring the fact that an error occurred!

    Perl’s support for C++ is rather weak. That shouldn’t be that surprising; perl was written in C and targets C for its external subroutines.

    My suggestion: Do handle exceptions, but do not use that rather klunky exception stuff provided for ‘free’ from xsubpp. Instead write the try ... catch ... block yourself. Make the catch block convert those caught C++ exceptions to perl exceptions. Call Perl_croak for fatal errors, Perl_warn for non-fatal errors.

    And good luck. Interfacing perl to C/C++ is not easy.

    Some potentially helpful links:

    • “How can I use a C++ class from Perl?” How can I use a C++ class from Perl?
    • “Gluing C++ And Perl Together”, http://www.johnkeiser.com/perl-xs-c++.html
    • “Interfacing Perl with C++, using XS”, http://adventures-in-perl.blogspot.com/2010/08/interfacing-perl-with-c-external-files.html
    • “Auto-inserting wrappers to handle C++ exceptions”, http://www.mail-archive.com/perl-xs@perl.org/msg02248.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to install Net::Arping package using cpan and I can't do that
Fedora 14 $ uname -a Linux giles 2.6.35.13-92.fc14.i686 #1 SMP Sat May 21 17:39:42

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.