Skip to content

Commit

Permalink
Fix exception feature (broken since #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Oct 1, 2021
1 parent 6d7ddbc commit 4cabdb9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions objc2/src/exception.rs
Original file line number Diff line number Diff line change
@@ -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`

Expand All @@ -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<R>(closure: impl FnOnce() -> R) -> Result<R, Id<Exception>> {
r#try(closure).map_err(|e| Id::new(NonNull::new(e).unwrap()))
pub unsafe fn catch_exception<R>(
closure: impl FnOnce() -> R,
) -> Result<R, Option<Id<Object, Shared>>> {
r#try(closure).map_err(|e| NonNull::new(e).map(|e| Id::new(e.cast())))
}
6 changes: 3 additions & 3 deletions objc2/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})
};
Expand Down

0 comments on commit 4cabdb9

Please sign in to comment.