[erlang-questions] Why I love Erlang (part 57)
Richard A. O'Keefe
Tue Apr 23 02:12:38 CEST 2013
"Part 57" is a joke, but it feels serious.
I'm teaching some students who have to use Objective C for a project,
although I'm not actually teaching them Objective C.
Objective C has a @try/@catch/@finally block which is practically
identical to Java's. Except for one thing, well, two things that are one.
(1) The Cocoa frameworks require that all exceptions be instances of
NSException or its subclasses. Do not throw objects of other types.
So the language and compiler will allow you to @throw other things,
it's just that that won't work if you're using any of the things
that would be reasons for using Objective C in the first place.
(2) The Cocoa frameworks are generally not exception-safe. The general
pattern is that exceptions are reserved for programmer error only,
and the program catching such an exception should quit soon afterwards.
So if the user interface calls back into your code, and your code
@throws something, when you catch it, you had better regard the user
interface as totally off limits -- in an undefined state -- from then
I just read that last night, and I am still shocked.
Now I find myself wondering if Java really does so much better,
or if Objective C is just more honestly documented.
Erlang never looked so good!
More information about the erlang-questions