Skip to content

Commit 4cabdb9

Browse files
committed
Fix exception feature (broken since #21)
1 parent 6d7ddbc commit 4cabdb9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

objc2/src/exception.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use core::ptr::NonNull;
22

3-
use crate::rc::Id;
3+
use crate::rc::{Id, Shared};
44
use crate::runtime::Object;
5-
use objc2_exception::{r#try, Exception};
5+
use objc2_exception::r#try;
66

77
// Comment copied from `objc2_exception`
88

@@ -21,6 +21,8 @@ use objc2_exception::{r#try, Exception};
2121
/// undefined behaviour until `C-unwind` is stabilized, see [RFC-2945].
2222
///
2323
/// [RFC-2945]: https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html
24-
pub unsafe fn catch_exception<R>(closure: impl FnOnce() -> R) -> Result<R, Id<Exception>> {
25-
r#try(closure).map_err(|e| Id::new(NonNull::new(e).unwrap()))
24+
pub unsafe fn catch_exception<R>(
25+
closure: impl FnOnce() -> R,
26+
) -> Result<R, Option<Id<Object, Shared>>> {
27+
r#try(closure).map_err(|e| NonNull::new(e).map(|e| Id::new(e.cast())))
2628
}

objc2/src/message/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ macro_rules! objc_try {
1414
($b:block) => {
1515
$crate::exception::catch_exception(|| $b).map_err(|exception| {
1616
use alloc::borrow::ToOwned;
17-
if exception.is_null() {
18-
MessageError("Uncaught exception nil".to_owned())
17+
if let Some(exception) = exception {
18+
MessageError(alloc::format!("Uncaught exception {:?}", exception))
1919
} else {
20-
MessageError(alloc::format!("Uncaught exception {:?}", &**exception))
20+
MessageError("Uncaught exception nil".to_owned())
2121
}
2222
})
2323
};

0 commit comments

Comments
 (0)