Files
ghostty/macos/Sources/Helpers/ObjCExceptionCatcher.m
2026-02-25 09:00:52 -08:00

30 lines
1.0 KiB
Objective-C

#import "ObjCExceptionCatcher.h"
#import <AppKit/AppKit.h>
BOOL GhosttyAddTabbedWindowSafely(
id parent,
id child,
NSInteger ordered,
NSError * _Nullable * _Nullable error
) {
// AppKit occasionally throws NSException while reparenting tabbed windows.
// We must catch it in Objective-C; letting this cross into Swift is unsafe.
@try {
[((NSWindow *)parent) addTabbedWindow:(NSWindow *)child ordered:(NSWindowOrderingMode)ordered];
return YES;
} @catch (NSException *exception) {
if (error != NULL) {
NSString *reason = exception.reason ?: @"Unknown Objective-C exception";
*error = [NSError errorWithDomain:@"Ghostty.ObjCException"
code:1
userInfo:@{
NSLocalizedDescriptionKey: reason,
@"exception_name": exception.name,
}];
}
return NO;
}
}