Re: Try/Catch

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

In 99.99 % (or thereabouts) of cases the programmer will NOT know what that correct runtime value is. Insisting otherwise is completely absurd!

You're not going to try to provide a value for a bad index..

Right. Neither Exceptions nor SCC can do this any better than the other. So the comments implying that Exceptions could solve a bad index better than SCC were muddying the waters just a bit, eh? This is what was written:

dcuny said...
Spock said...

I think the problem of a bad index is a very poor example to solve using try/catch.

Why is it a poor example? It's the typical exception in Euphoria.

Spock said...

So you catch a bad index. Now what?

By definition, the code traverses up the call stack until it finds a catch clause to handle it.

Have you looked into how try/catch works before arguing against it?

- David

But of course. Although I never needed to use exceptions in the past that doesn't disqualify me from being able to reason about the subject logically.

dcuny said...

.. For example, here's the "recovery" on an attempt to open a file that failed because of some exception:

... 
case OPEN_FILE then 
   try 
      open_file(fileName) 
   catch e 
      alert("The file " & fileName & " could not be opened. " & e[EXCEPTION_MESSAGE]) 
   end try 
... 

In this instance try/catch has become like a mere proxy for if/then. So my point is that status codes will do just as good a job (at this low level).

dcuny said...

On the other hand, a developer might simply try to prevent their program from dying by wrapping the top level:

-- handle events until exitProgram is true 
while not exitProgram do 
   -- is there an event to process? 
   if eventInQueue() then 
      try 
         -- handle the event 
         process( getEvent() ) 
      catch e 
         alert(e[EXCEPTION_MESSAGE]) 
      end try 
   else 
      -- release the cpu 
      pause() 
   end if 
end while 

It's up to the developer to decide at what level it is appropriate to try to catch exceptions. Generally, these will be fairly high up - not at the low level that you're focusing on.

- David

Because you were referring to things like "[bad indexes are] the typical exception in Euphoria." this is why I was focusing on that low level aspect. For the high level this can still be done with SCC. Only that the traversal path must be manually coded. Still, no tricky stack unwinding is needed. Just return the functions via an error path. Granted. More verbose (what Jim calls 'ugly') but, I think, very robust.

Spock

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

Search



Quick Links

User menu

Not signed in.

Misc Menu