7

What is the difference between @throw NSException and NSException raise? I wonder which one I should rather use (there is a proper use case to use one) and why?

KlimczakM
  • 12,576
  • 11
  • 64
  • 83

1 Answers1

7

From Apple docs,

An important difference between @throw and raise is that the latter can be sent only to an NSException object whereas @throw can take other types of objects as its argument (such as string objects). Cocoa applications should @throw only NSException objects.

Typically you throw or raise an exception inside an exception-handling domain, which is a block of code marked off by the @try compiler directive.

See “Handling Exceptions” for details.

Within exception handling domains you can re-propagate exceptions caught by local exception handlers to higher-level handlers either by sending the NSException object another raise message or by using it with another @throw directive.

For further details you can refer the documentation.

Community
  • 1
  • 1
ChenSmile
  • 3,401
  • 4
  • 39
  • 69