Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception types #21

Open
SirCipher opened this issue Sep 27, 2023 · 0 comments
Open

Add exception types #21

SirCipher opened this issue Sep 27, 2023 · 0 comments
Assignees
Labels

Comments

@SirCipher
Copy link
Member

SirCipher commented Sep 27, 2023

Implement an exception type that can be used for throwing exceptions in the rust runtime.

trait JavaException {
    type Exception<'l, 'c>: Desc<'l, JClass<'c>>;

    fn lookup(env:&JniEnv) -> Result<Self::Exception, JniError>;
}

Which would allow Scope::throw_new to accept JavaException as a type parameter:

pub fn throw_new<E>(&self, msg: S)
where
    E: JavaException
{
    let Scope { vm, env, .. } = self;
    system_call(vm, || {
        let desc = E::lookup(env)?;
        env.throw_new(desc, msg)
    })
}

Usage as:

struct RuntimeException;
impl JavaException for RuntimeException {
...
}

scope.throw_new::<RuntimeException>("...");
@SirCipher SirCipher added the rust label Sep 27, 2023
@SirCipher SirCipher self-assigned this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant