Re: Try/Catch

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

function foo(sequence s) with spec -999
return length(s[1..$ - 5]) > 2
end function

So you still have to catch it at the function level.

This seems to me less compelling than try/catch:

  1. No obvious implementation at the compiler level
  2. What happens with a procedure?
  3. try/catch provides a block of code, rather than a return value
  4. Need to invent error code values for each function (clunky when dealing with indexing)
  5. Have to add if/then after every call
  6. Unlike try/catch will not "bubble up" to appropriate level

- David

Yes, I do have to catch it in the function level - but only in the low-level implementation. The high-level implementation will only return error codes.

  1. Developer needs to do some deep thinking before implementing new ideas.
  2. Use only functions to deal with exceptions - not procedures.
  3. Return value from function is already part of Euphoria - why introducing a new and complex programming method to the end users? (and overhead is part of any high-level programming technique).
  4. Honestly, David, dealing with exceptions, using any possible method, is an art - it can never be done in a standard way. For example, in Assembly, when Carry Flag is set then what your program is doing?... It's only depends on what the program wants to do. It's like an art.
    So using error codes is the same, it's just that the end-user is already very-very familiar with this simple approach. When you really afraid of a specific indexing situation - place it in a different function which returns your desired error code (object).
  5. if...then is used everywhere anyway. It's less confusing then try/catch. In case I must call a function 1000 times, from too many places, I'll use another procedure or function to call that function, with the proper if..then. I already do it in these cases.
  6. I believe that dealing with returned error code immediately, is a much more reliable/logical technique. It might force some programmer to change their programming habits. Personally I believe that logical approach is more "Euphorian" then complex approach, which might be common in other languages. I don't offer something new to Euphoria: open(), dir(), seek(), etc, already using this approach, and we already using if...then to deal with it very clearly and easily.

p.s. If you felt insulted by me in previous posts... I'm sorry. It surely not your fault, it's all my fault since I'm a bit aggressive (my wife has to remind me that 30 times a day). So sorry.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu