(
self,
class: impl Desc<'a, JClass<'a>>,
block: impl FnOnce(JThrowable<'a>) -> Result<T, Error>,
)
| 41 | |
| 42 | impl<'a: 'b, 'b, T> TryCatchResult<'a, 'b, T> { |
| 43 | pub fn catch( |
| 44 | self, |
| 45 | class: impl Desc<'a, JClass<'a>>, |
| 46 | block: impl FnOnce(JThrowable<'a>) -> Result<T, Error>, |
| 47 | ) -> Self { |
| 48 | match (self.try_result, self.catch_result) { |
| 49 | (Err(e), _) => Self { |
| 50 | env: self.env, |
| 51 | try_result: Err(e), |
| 52 | catch_result: None, |
| 53 | }, |
| 54 | (Ok(Ok(r)), _) => Self { |
| 55 | env: self.env, |
| 56 | try_result: Ok(Ok(r)), |
| 57 | catch_result: None, |
| 58 | }, |
| 59 | (Ok(Err(e)), Some(r)) => Self { |
| 60 | env: self.env, |
| 61 | try_result: Ok(Err(e)), |
| 62 | catch_result: Some(r), |
| 63 | }, |
| 64 | (Ok(Err(Error::JavaException)), None) => { |
| 65 | let env = self.env; |
| 66 | let catch_result = (|| { |
| 67 | if env.exception_check()? { |
| 68 | let ex = env.exception_occurred()?; |
| 69 | let _auto_local = env.auto_local(ex.clone()); |
| 70 | env.exception_clear()?; |
| 71 | if env.is_instance_of(ex, class)? { |
| 72 | return block(ex).map(|o| Some(o)); |
| 73 | } |
| 74 | env.throw(ex)?; |
| 75 | } |
| 76 | Ok(None) |
| 77 | })() |
| 78 | .transpose(); |
| 79 | Self { |
| 80 | env, |
| 81 | try_result: Ok(Err(Error::JavaException)), |
| 82 | catch_result, |
| 83 | } |
| 84 | } |
| 85 | (Ok(Err(e)), None) => Self { |
| 86 | env: self.env, |
| 87 | try_result: Ok(Err(e)), |
| 88 | catch_result: None, |
| 89 | }, |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | pub fn result(self) -> Result<T, Error> { |
| 94 | match (self.try_result, self.catch_result) { |
no outgoing calls