You're asuming that the exception is stored together with the value?
1. Well, I wouldn't call it "assuming", I'm just sketching a possibility. We already have something like this, except that no real information about the nature of the exception is included.
2. I said from the start that I'm not sure this whole kind of approach -- trapping exceptions as values implicitly, by any means, as in your example, my example, or the existing zero_type hack -- is a good idea. But you asked me for suggestions, and I gave one I thought was reasonable, assuming we wanted to try the trap-exception-as-value approach.
3. It's not the exception itself that is stored, it's a "hidden record" (or whatever we might want to call it) of the exception. I meant that things that use the zero_type hack today could be extended to use this kind of system, instead of throwing exceptions. Then real exceptions could perhaps be thrown as objects, behaving like traditional "backtrace" arrays when indexed with integers, and behaving in the new way when indexed with other values.
4. It's not exactly stored "together" with the value, since the value and the exception record are mutually exclusive. If the evaluation went alright, without exceptions, there is no exception record, and if the evaluation was interrupted by an exception, there is no value, just an exception record.
That's not how exceptions work in any language I'm familiar with,
It's a bit like how conditionals work in PL/1, I think. :-) But I didn't mean for us to change "thrown" exceptions to work that way, just to merge the zero_type hack with an enhanced exception system. I mean, a new exception system is desirable anyway, and unifying the zero_type hack with it would be nice, especially if it could be done in a way that doesn't break existing code (or at least doesn't break normal existing code; unusually zero_type-aware code might run the risk of being broken, but I don't think that kind of code is particularly common, if it exists at all outside of test cases).
/ Leif Stensson, Lysator
Previous text:
2003-01-28 14:19: Subject: Re: zero_type() & UNDEFINED and _typeof()
Huh?
value_with_default(m->foo, "bar");
You're asuming that the exception is stored together with the value? That's not how exceptions work in any language I'm familiar with, it would be raised when the value is computed, terminate the normal flow of control, and the helper function would never be called.
I'm afraid I'm totally lost here, even if storing arbitrary exceptions with a value would be a creative extension of the zero_type hack.
/ Niels Möller ()