0

I get the following error in XCode...

enter image description here

I've added a "Swift Error" breakpoint and left the "Type" box empty. I thought this might show some further info, but it doesn't appear to have any effect.

How can I find out where this error is arising from?

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
  • 1
    `Swift Error` breakpoints consider only **thrown** errors. Set the exception breakpoint. But I guess the function returns `nil` and the exclamation mark crashes the app. Learn how to handle optionals safely. – vadian Jan 30 '17 at 15:04
  • No, the error is coming from somewhere deep inside toJSONString. I got bored tying to step through to it. – Ian Warburton Jan 30 '17 at 15:06
  • Sorry, you're right. The exclamation mark does in fact crash the app. I wonder why its nill. – Ian Warburton Jan 30 '17 at 15:10
  • Yes, if the runtime error occurs in this line `toJSONString()` returns `nil`. Use the debugger. – vadian Jan 30 '17 at 15:10
  • The code says its not a valid JSON object for some reason. I think that situation should result in an un-handled error being propagated rather than merely returning nil. – Ian Warburton Jan 30 '17 at 15:18
  • ... that would force me to deal with the situation close to where it has arisen and give me specific information about why the undesired result has occurred. – Ian Warburton Jan 30 '17 at 15:23

1 Answers1

4

EXC_BAD_INSTRUCTION means that you have an invalid assertion (usually a force-unwrapped nil, though a bad cast could also be the culprit, here). Make sure that tourDto is a populated var, and that it can be cast to whatever toJSONString() returns (I'm not familiar with that method, and it could also be the culprit).

dylanthelion
  • 1,760
  • 15
  • 23
  • Also, here, I looked up a related SO post, where someone was experiencing a similar problem, with a different method: http://stackoverflow.com/questions/28804654/what-does-error-thread-1exc-bad-instruction-code-exc-i386-invop-subcode-0x0 – dylanthelion Jan 30 '17 at 15:09