-1

I used to work in .NET c# and recently I started learning objective-c and iOS programming. Several times I've read that objective-c is exception unfriendly and I shouldn't handle them. I know it's better to don't cause any exception, but aren't they created for securing our code? Exception handling is very common in .NET and I can't understand why I shouldn't do this in objective-c.

demongolem
  • 9,474
  • 36
  • 90
  • 105
KlimczakM
  • 12,576
  • 11
  • 64
  • 83
  • In "What are the best practices for exceptions/returning NO/nil in Objective-c?" nobody explain WHY I should't use them. And "Why should I not wrap every block in “try”-“catch”" still doesn't explain why exception handling in objective-c is less recommended that in for example .NET (as it is obvious not to overuse it). – KlimczakM Dec 20 '13 at 08:46
  • 1
    It has little to do with ObjC, and everything to do with Cocoa. Internally, Cocoa does not wrap everything in @try/@catch/@finally, so if Cocoa calls into your code, it is not prepared for your code to throw an exception, even if you later catch it. – Catfish_Man Jul 16 '14 at 21:15

1 Answers1

3

Even in .NET, exceptions are not meant for program flow. The fact that some programmers use them as such is just bad programming. The performance is terrible. Often you will see programs that display error messages from exception handling that make no sense to the end user. This kind of design makes an application not crash, but does not offer an end user much information.

You can use exceptions as program flow just like you do in .NET. There is nothing stopping you. The performance hit is probably actually less than in .NET.

The reason you shouldn't is because those exceptions happen for a reason. You aren't using the frameworks appropriately. You haven't implemented something fully. Etc.

Fruity Geek
  • 7,351
  • 1
  • 32
  • 41