Re: Try/Catch
- Posted by jimcbrown (admin) Feb 12, 2015
- 4442 views
Spock's smart error code which is available to the caller is the real thing. I would say that using only functions for retrieving the smart error code is even more mature. No need to wrap the whole program/plug-in with error handler. If it's that bad - then get rid of it.
The "smart error code" only works for a limited set of exceptions, ignores the most common cases, and continues to run code when Euphoria knows that the results will be wrong.
Since incorrect indexes are the most common exception in Euphoria, you're suggesting that we adopt a solution known to leave the majority of use cases in place.
These claims are extremely confused.
Smart Status Code can be activated in any called routine/operation that might care to throw an error. It is a lot like the error codes of the GO language (which abhors exceptions). The returned code can indicate different levels of severity. The most severe ones will prompt the compiler to insist that the caller handle it. This could mean correcting the bad data OR propagating the error up to the next calling level OR even resetting the status code.
The implication that Exceptions can somehow handle bad indexes better than SSC is just a red herring.
Spock
I think I can see how this would work.
Say we do this:
sequence s = "" object x = s[1]
Since it's an invalid index, we return a special value. It's represented by a new builtin constant, ERR_IDX.
? x
Output:
{{{ ERR_IDX }}}}
So, you can test x to see if the slice was successful, or if an error occured. (Internally, for OE, we'd use one of the remaining unused type codes to represent errors, and the rest of the bits would just be an enum for each kind of error we coudl return.)
We'd also have a global builtin variable, called ErrNo. Everytime a function returns with one of the builtin error constants, or an operation like slicing returns an error constant, ErrNo gets set to the same value.
If a procedure is called and has an error, ErrNo is also set.
These special constants would be designed so that one could assign them to an atom, an integer, or a sequence. So any variable could safely hold one of these values.
That said, I think this is much uglier than try/catch. dcuny, you can take it from here.