2

Is there any function like this

void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)

like in windows phone,for handling all exceptions to send to my server

vadian
  • 274,689
  • 30
  • 353
  • 361
Narek Simonyan
  • 572
  • 1
  • 7
  • 18

1 Answers1

2

You can set NSSetUncaughtExceptionHandler in your AppDelegate, refer to this post

But Swift does not fully support it, as explain in this post, you need to do it in Objective-C

EDIT

Thanks for Martin R's comment, Swift now supports it.

Community
  • 1
  • 1
zc246
  • 1,514
  • 16
  • 28
  • 3
    As of Swift 2, you can set NSSetUncaughtExceptionHandler in Swift as well, see the second answer http://stackoverflow.com/a/31770435/1187415. – Martin R Nov 10 '15 at 12:59
  • 3
    But note that this catches only NSExceptions, not errors thrown in Swift or Swift runtime errors. – Martin R Nov 10 '15 at 13:02
  • Thanks,i found what I want,and as @MartinR said its not catching errors like array out of range etc... – Narek Simonyan Nov 10 '15 at 14:50
  • @MartinR Does the Swift runtime run top of the Objc runtime and that's why setting NSSetUncaughtExceptionHandler will not catch a Swift runtime error like array index out of bounds? – Crystal Jan 04 '18 at 19:30
  • @Crystal: No, it doesn't. – Martin R Jan 05 '18 at 20:11