Why invalidArgumentException crashes application?

If I use this on an iOS project, the application crashes. Why invalidArgumentException could not be handled via try and catch?

Tested with 2022R2 and 2022R3 (Build 57964)

var MyLocation as MapLocation
var MyLocArray() as MapLocation

try
for i as double = 1.0 to 49.0 step 0.5
MyLocation = New MapLocation(i, i, “MyLoc”)
MyLocArray.Add(MyLocation)
next

MapViewer1.AddLocation(MyLocArray)

Catch
var e as InvalidArgumentException
MessageBox CurrentMethodName + " Error: " + e.Message
end try

What do you get in e when debugging this:

var MyLocation as MapLocation
var MyLocArray() as MapLocation

try

  for i as double = 1.0 to 49.0 step 0.5
    MyLocation = New MapLocation(i, i, “MyLoc”)
    MyLocArray.Add(MyLocation)
  next

  MapViewer1.AddLocation(MyLocArray)

Catch e
  MessageBox CurrentMethodName + " Error: " + e.Message

end try

Was your intention something like this?

Catch e as InvalidArgumentException
   MessageBox CurrentMethodName + " Error: " + e.Message
end try

Looking at your code, why are you trying to use the same exact identifier (MyLoc) over and over? My recollection is that they are supposed to be unique.

Also, are you sure that the exception you are getting is an InvalidArgumentException? If it’s something else (like NilObjectException) you’ll still crash.

Another possibility is that you’re hitting an uncaught NSException. Do you have a crash log that we could see? The first 100 lines should be fine.

Sorry, these are the correct lines.

Catch e as InvalidArgumentException
MessageBox CurrentMethodName + " Error: " + e.Message
end try

But the result is the same. Application should show a message an not crashes.

You got this message from the core location, if your network is not available or you have send too many request to the apple map server (see this message on stackoverflow)

The same problem exists with UnsupportedOperationException.

catch e as UnsupportedOperationException

Not sure what you call crash.

Do you have break on exceptions enabled? If you do you’ll pause in the debugger when the exception happens but can then resume and the try/catch will let you continue. Pausing in the debugger doesn’t mean the app has fully crashed

When the app in running in debug mode in Simulator or on a real device, that application has a full crash without any other information.