From 4cabdb95f1d9ffe355f8309afac7328759a81e8d Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 1 Oct 2021 15:49:10 +0200 Subject: [PATCH] Fix exception feature (broken since #21) --- objc2/src/exception.rs | 10 ++++++---- objc2/src/message/mod.rs | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/objc2/src/exception.rs b/objc2/src/exception.rs index 50013c70c..2465e3aa0 100644 --- a/objc2/src/exception.rs +++ b/objc2/src/exception.rs @@ -1,8 +1,8 @@ use core::ptr::NonNull; -use crate::rc::Id; +use crate::rc::{Id, Shared}; use crate::runtime::Object; -use objc2_exception::{r#try, Exception}; +use objc2_exception::r#try; // Comment copied from `objc2_exception` @@ -21,6 +21,8 @@ use objc2_exception::{r#try, Exception}; /// undefined behaviour until `C-unwind` is stabilized, see [RFC-2945]. /// /// [RFC-2945]: https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html -pub unsafe fn catch_exception(closure: impl FnOnce() -> R) -> Result> { - r#try(closure).map_err(|e| Id::new(NonNull::new(e).unwrap())) +pub unsafe fn catch_exception( + closure: impl FnOnce() -> R, +) -> Result>> { + r#try(closure).map_err(|e| NonNull::new(e).map(|e| Id::new(e.cast()))) } diff --git a/objc2/src/message/mod.rs b/objc2/src/message/mod.rs index 7cfe530d0..a46041286 100644 --- a/objc2/src/message/mod.rs +++ b/objc2/src/message/mod.rs @@ -14,10 +14,10 @@ macro_rules! objc_try { ($b:block) => { $crate::exception::catch_exception(|| $b).map_err(|exception| { use alloc::borrow::ToOwned; - if exception.is_null() { - MessageError("Uncaught exception nil".to_owned()) + if let Some(exception) = exception { + MessageError(alloc::format!("Uncaught exception {:?}", exception)) } else { - MessageError(alloc::format!("Uncaught exception {:?}", &**exception)) + MessageError("Uncaught exception nil".to_owned()) } }) };