-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.

2
  • 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). Commented Dec 20, 2013 at 8: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. Commented Jul 16, 2014 at 21:15

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.