Re: Try/Catch

new topic     » goto parent     » topic index » view thread      » older message » newer message
jimcbrown said...
Spock said...
dcuny said...
Shian_Lee said...

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 }}}}

No.

Two values are returned. The status code is returned in parallel to the function return. This also means it'll work for procedures etc..

In your example it'd be:

sequence s = "" 
object x = s[1] -- no crash 
? x -- {} 
? ERRNO -- BAD_INDEX 
 

However, I think bad indexes are a poor example (in the context of the topic) since they are programming errors that must be corrected rather than somehow "managed". Certainly, in program development a bad index should cause a crash so I can fix the problem. For program deployment the behaviour will revert to above (with signalling).

Spock

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu