Working around error in NSSpeechSynthesizerMBS

I have two users who have reported an error when creating a new NSSpeechSynthesizerMBS. This is the line of code in Xojo subclassing
NSSpeechSynthesizerMBS as a window property:

myNSSpeechSynthesizerMBS = new NSSpeechSynthesizerMBS()

This is the error message and the relevant portion of the error trace:

Error message: error A Cocoa NSInvalidArgumentException was not handled: -[NSNull firstObject]: unrecognized selector sent to instance 0x7ff852f40a90

Trace:

RuntimeRaiseException
_Z19RaiseNSExceptionMBSP11NSException
_ZL13initWithVoiceP16REALobjectStructP16REALstringStruct
NSSpeechSynthesizerMBS.Constructor%%o

Both are running macOS 14.5.

One user sees an error in System Settings when trying to access Speech preferences (I don’t know about the other), so I assume the exception is being thrown in the Constructor.

I’d like to trap that exception and return nil, then deal with a nil object in code, but I don’t know how to do that. I tried

try
myNSSpeechSynthesizerMBS = new NSSpeechSynthesizerMBS()
exception err
  return
end try

but it the user reports the same error trace.

Any suggestions?

Sorry, no idea why this happens.

If you pass no voice, we use default voice.
You get NULL there, maybe there is no default voice?
or the preferences for speech are broken and maybe point to a deleted voice?

I can make a build for him with a specified voice and see if that helps, thanks for the suggestion. So there is no way to catch an exception in the constructor?

BTW, when I follow the link on the MBS page to the Apple documentation, I see that almost all API calls are deprecated. Could this explain why all the people with issues are running 14.5 (I am, too, of course, with no problem).

The normal exception handler you have should catch it.

Like the one in the original post? The user I sent that build to had the same error as before. If you meant something else let me know. Thanks.

Yes, I see your try and catch there.

You can catch the NSExceptionMBS and if it happens there, maybe disable the speech feature in the application.

Thanks for the suggestions.

For anyone else with this particular problem, the issue appears to be a Sonoma-related bug involving a corrupted .plist. Deleting the file fixed it for him.

https://discussions.apple.com/thread/255622280?answerId=260474528022&sortBy=best#260474528022