I learned that Objective-C has an equivalent way of handling exceptions like C# does in .NET.
Furthermore as the apple docs says, I’d like to handle/process exceptions, creating an NSError-object.
Taking a close look at the section “Catching Different Types of Exception”
in the docs exception handling
….I would like to catch different types of exception. In .NET I am used to browse the doc of a class-method to get the possible exceptions it can raise.
Where to get this information from the apple-docs?
How do I know, what kind of exceptions a -method/object/process- can raise?
As Apple’s documentation says, most exceptions are thrown in exceptional circumstances. (Some exceptions aren’t, like accessing an object out of NSArray bounds.)
.NET encourages local exception handling. Cocoa is written to encourage large-scope exception handling. The reason you have local exception handling in .NET is that you expect some part to fail in an expected way (like a network error when downloading something). In Cocoa, this is handled by using methods that return NSErrors instead. It’s the same thing, only more visible in the method signature.
A good rule of thumb is that Cocoa only throws an exception in situations where it’s unclear how you would even recover. (Don’t mistake this for exceptions being thrown all over the place like in .NET and being this difficult to handle.)