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

  • Home
  • SEARCH
  • 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 7511707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:38:02+00:00 2026-05-29T23:38:02+00:00

Perhaps I’m being too ambitious here, but I’m trying to pass a shared_ptr back

  • 0

Perhaps I’m being too ambitious here, but I’m trying to pass a shared_ptr back to Java through an Exception like so.

I am able to catch the Exception in java, but when I try to access any methods in the ManagementProcessor object itself I get a SIGSEGV. If I use new ManagementProcessorPtr() to send in an empty one I get the correct behavior (I throw a different exception).

Any insights?

Thanks!

-Chip

typedef boost::shared_ptr<ManagementProcessor> ManagementProcessorPtr;

%include "boost_shared_ptr.i"
%shared_ptr(ManagementProcessor);
%typemap(javabase) Exception "java.lang.RuntimeException";
%typemap(javabase) AuthenticationExceptionManagementProcessor "NS/Exception";

%exception {
try {
  $action
}
catch (AuthenticationException<ManagementProcessor> & e ) {
  jclass eclass = jenv->FindClass("NS/AuthenticationExceptionManagementProcessor");
  if ( eclass ) {
    jobject excep = 0;
    jmethodID jid;

    jstring message =  jenv->NewStringUTF(e.getMessage().c_str());
    jstring file =  jenv->NewStringUTF(e.getFileName().c_str());

    ManagementProcessorPtr* realm = new ManagementProcessorPtr(e.getRealm());
    jlong jrealm;
    *(ManagementProcessorPtr **)&jrealm = realm;

    jid = jenv->GetMethodID(eclass, "<init>",
        "("
        "LNS/ManagementProcessor;"
        "J"
        "Ljava/lang/String;"
        "Ljava/lang/String;"
        "J)V");
    if (jid) {
        excep = jenv->NewObject(eclass, jid,
            jrealm,
            e.getApiErrNum(),
            message,
            file,
            e.getLineNum());
        if (excep)  {
            jenv->Throw((__jthrowable*) excep);
        }
    }
  }

Client code:

} catch (AuthenticationExceptionManagementProcessor e) {
        java.lang.System.err.println(e);
        ManagementProcessor mp = e.getRealm();
        java.lang.System.err.println("got mp");
        java.lang.System.out.println(mp.getUUID());

}

  • 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-29T23:38:03+00:00Added an answer on May 29, 2026 at 11:38 pm

    And of course the right answer is that first I have to create the Java ManagementProcessor object with the ctor that takes a CPtr:

    jclass mpclass = jenv->FindClass("NS/ManagementProcessor");
    jobject jmp = 0;
    jmethodID mpid;
    ManagementProcessorPtr *realm = new ManagementProcessorPtr(e.getRealm());
    jlong jrealm;
    *(ManagementProcessorPtr **)&jrealm = realm;
    mpid = jenv->GetMethodID(mpclass, "<init>", "(JZ)V");
    jmp = jenv->NewObject(mpclass, mpid, jrealm, true);
    

    …

            excep = jenv->NewObject(eclass, jid,
                jmp,
                e.getApiErrNum(),
                message,
                file,
                e.getLineNum());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps what I'm trying to explain here doesn't make any sense, so I'd like
Perhaps there is a better way to do this, but here's where I'm at
Perhaps I'm misapplying Unity, but here goes. I have a couple of applications, both
Perhaps i am being stupid by asking this just now, but... I notice that
Perhaps I'm missing something here, but it seems that anything in the object model
Perhaps I'm missing something here, but I want the user to be able to
Perhaps not the best title, but here is the issue. We are creating a
Perhaps I'm using the OpenFileDialog incorrectly, but I've found that unhandled exceptions are being
Perhaps i'm misunderstanding here, but given the following html: <select value=2> <option value=1>Something</option> <option
Perhaps I'm missing a major point of the x64 platform here, but my perception

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.