3 ms·
The heuristic is that if the case is more frequent than something like 1/1000 then you don't use exceptions in these languages (C++, Java, ...). As they are a l
by toolslive 12y ago
The heuristic is that if the case is more frequent than something like 1/1000 then you don't use exceptions in these languages (C++, Java, ...). As they are a lot cheaper in languages like ML, people there tend to use them more for early exits out of things like folds.
A simple example:
let prod = List.fold_left (fun acc a -> acc * a) 1.0 xs
should not fold over the whole list if a factor is 0.0
so they tend to use exceptions for that (or delimited continuations)
- kyllo 12y agoJava doesn't really give you a choice though, because so many of the standard library classes have exceptions baked in. Any code you write related to file I/O for example will have to have either a "throws" or a "try/catch" on it, or else it won't even compile.
- judk 12y agoChecked exceptions are much closer to "error codes" than unchecked exceptions. Checked exceptions just loosen the constraint a bit and let you defer handling to anywhere the caller's remaining function scope (or explicitly continue the throw)