Xcode 15 Beta 6 objc @try @catch runtime error

I was migrating from Xcode 14 -> 15, and noticed that my code was failing with dyld[46534]: Symbol not found: _OBJC_CLASS_$_NSError

I was able to debug the problem to some old objective c code, as documented in this thread: https://github.com/RonRadtke/react-native-blob-util/issues/273

The error seems to stem from this particular try catch block

@try {
    // Some code
}
@catch(NSError *er) {
    // handle error
}

When I convert the code to catch an NSException instead, the runtime error goes away. Understandably, according to the apple docs, it should be throwing an NSException in the first place, but the documents do say

Important: Although you can throw and catch objects other than NSException objects, the Cocoa frameworks themselves might only catch NSException objects for some conditions. So if you throw other types of objects, the Cocoa handlers for that exception might not run, with undefined results. (Conversely, non-NSException objects that you throw could be caught by some Cocoa handlers.) For these reasons, it is recommended that you throw NSException objects only, while being prepared to catch exception objects of all types.

So it seems like this should not have produced a runtime error. I wanted to flag this in case the underlying code behind the @try @catch changed unintentionally.

It’s certainly true that throwing, and hence catching, an NSError is a mistake, but I’m curious about the link error you’re getting. It seems to indicate that the code is trying to find the NSError class, and that should be available. When I put your snippet into a small command-line tool test project and build it with Xcode 15.0b6, I see this:

% nm -m Test735610 
                 (undefined) external _OBJC_CLASS_$_NSError (from Foundation)
…

It’s importing the NSError class from Foundation, which is exactly where I’d expect to find it.

When you build this code into your real project, are you sure you link with Foundation?

Also, what platform are you building for? I’m building a macOS command-line tool, testing both Intel and Apple silicon, but perhaps the issue only shows up on some other platform.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

When trying to catch an NSObject, runtime error "dyld[2683]: Symbol not found: OBJC_CLASS$_NSObject" occurs.

https://github.com/jeroentrappers/flutter_keychain/issues/38

I am using Xcode 15 Beta 8.

the error can be replicated easily.

Hmmm, maybe I’m missing something but the discussion at that link involves complex third-party tooling, and there’s no guarantee that the issue isn’t triggered by some other aspect of that tooling.

I tried creating this in a trivial app:

  1. On macOS 13.5, I ran Xcode 15.0b8.

  2. I created a new test project from the iOS > App template. I selected Objective-C as the language and Storyboard as the UI.

  3. I added this code to the end of the -viewDidLoad method:

    @try {
        // Some code
    }
    @catch(NSError *er) {
        // handle error
    }
    
  4. I ran the app on the iOS 17.0 simulator. It ran just fine.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It was solved for us by using Xcode 15.1 beta1 !

Xcode 15 Beta 6 objc @try @catch runtime error
 
 
Q