This is not a "good reason". Having used languages with restartable
exceptions I can pretty much guarantee you that it is not only possible,
but often desirable to have restartable exceptions. Consider this use
case:
1. The software commences a procedure that is time-consuming and that
requires lots of memory.
2. In the middle of this it runs out of memory. An exception is raised.
In the Ruby (and many other languages) world, I'm boned. I have to
throw away all the time and memory spent to get where I am, free up
memory in some way, and then restart the whole thing. This could be a
non-trivial operation (and, indeed, for this use case, is defined as
such). In a world with restartable exceptions, however, the use case
continues thus:
3. The exception handler pops up a dialogue/prompt/whatever telling me
that memory is low. It suggests actions I can take to free up enough
memory. Let's say I choose to kill memory hogs like Firefox or
OpenOffice.org. I click "continue" (or type or whatever the UI is).
4. The exception handler retries the very line of code that failed. All
of the expensive, time-consuming setup that led to that point is still
there and still ready for action.
(Please note at this point that this is only one example. I could
probably, given an hour, come up with a hundred situations in which
restartable exceptions are useful and desirable. Too, the handler's
actions are only one of a thousand possible reactions it could have.
Maybe for efficiency's sake I'm memoizing a whole bunch of calculations.
If I run out of memory in this case, the handler could clear the LRU
memo cache entries for twice the amount of reported memory being claimed
as a quick heuristic. This would be totally transparent to the user
except for a slight hiccough in performance.)
Now it is possible in the Ruby model to partition things in many
situations such that a retry only executes a small amount of code
instead of the huge setup alluded to above. This is a problem, however,
for several reasons:
1. You're putting in unnecessary scaffolding code solely because of the
language's shortcomings. (Shades of C++ and Java here, albeit very,
very, very minuscule shades.) This clutters code, constrains
architecture and generally is, to my eyes, anti-Ruby.
2. Not all problems can be built this way. For those problems which
cannot be set up this way, you're boned.
3. Most importantly, you're constraining your very thinking about
problems. There will be approaches to problems you simply will not
think of because the very language conspires against your thinking down
those lines.
···
On Sat, 2008-06-14 at 06:09 +0900, Robert Klemme wrote:
There is no way - and for good reason. An exception is thrown because
execution cannot proceed at that line.
--
Michael T. Richter <ttmrichter@gmail.com> (GoogleTalk:
ttmrichter@gmail.com)
Politics is the art of looking for trouble, finding it whether it exists
or not, diagnosing it incorrectly, and applying the wrong remedy.
(Ernest Benn)