Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
x/mobile: accessing field on nil on iOS raises exception instead of panicking (gomobile) #23511
The spec says accessing a field (
Please answer these questions before submitting your issue. Thanks!
What did you do?
If possible, provide a recipe for reproducing the error.
Here's an example that works fine in a regular Go program but the equivalent compiled into an iOS app crashes: https://play.golang.org/p/KsIyVll7NE0.
What did you expect to see?
Accessing a field on nil panics, and is handled by a surrounding defer/recover block.
What did you see instead?
Accessing a field on nil raises a native exception, crashing the program unrecoverably.
Ah, interesting! I hadn't tried running it outside of Xcode. Continuing execution in Xcode doesn't work (just stays at the same exception), but if I run outside of Xcode, catching the panic works and the program functions normally.
So it seems like the issue is that Xcode's debugger is probably installing a signal handler that conflicts with how panics get caught.
OK, so to summarize then, there are two distinct ways this is a (minor) problem:
@eliasnaur Yes. I tried:
My go version is go1.11 and gomobile is newest.
my test go file:
One other thing. When I catched a panic in go code, iOS system still report a crash log, but app not crash.
I see. So your app is actually able to continue (outside Xcode) if you catch the panic? If so, that's expected and not likely to change in the near future. Perhaps the Go runtime will need to use mach exception handlers for for panics instead of using the posix signal functions.
It just occurred to me that the
I hit this today, a simple example:
If you disable
I have not found a way to catch and ignore this in swift. It would be ideal if