Skip to content

Commit

Permalink
Throw exception from Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
YAMAMOTO Yuji committed Apr 16, 2020
1 parent 6a8de4e commit fec583d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions android_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ fn java_test() {
let class_ref = o_class.as_ref().unwrap();
let class = class_ref.as_obj();
// Call java code.
env.call_method(*class, "Test", "()V", &[])
.unwrap();
match env.call_method(*class, "Test", "()V", &[]) {
Ok(_) => {}
Err(jerr) => {
let k = jerr.kind();
if let ErrorKind::JavaException = k {
let jex = env.exception_occurred().unwrap();
env.throw(jex).unwrap();
} else {
error!("Unexpected kind of JavaException: {}", k);
}
}
}
}

0 comments on commit fec583d

Please sign in to comment.