Re: Error Trapping

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

Bernie Ryan wrote:

[in response to Ferlin's question about calling My_Procedure() with no
arguments]

>>global procedure My_Procedure(sequence Obj)
>>      puts(1,"You sent " & Obj & " to My_Procedure")
>>end procedure
>
> -- You don't need trap
>
>global procedure My_Procedure(sequence Obj)
>
>  -- take some corrective action or return and error condition
>  if obj = {} then
>    return -1
>  end if
>
>  puts(1,"You sent " & Obj & " to My_Procedure")
>
>end procedure

In this example, a call to My_Procedure() with no arguments will not even
get past the compile stage, so your "corrective action" will not have the
effect you intended. The empty sequence {} is *not* equivalent to "no
argument passed" -- Euphoria requires the programmer to specify *all* of a
routine's parameters on each call, even when you're calling them with
call_func() or call_proc().

[ADDITIONAL NITPICKY POINTS: Your "if" statement would result in the
"true/false condition must be an ATOM" error. It should read "if equal(Obj,
{})" or "if compare(Obj, {}) = 0" instead. Also, My_Procedure can't return a
 -1, because it's a procedure -- not a function.]


Be seeing you,
   Gabriel Boehme


 ------
What amuses me is that Picard has to ask for 'Tea. Earl Grey. Hot.'

This seems to mean:

1) The default value for Tea for the replicator is 'Cold'.

2) If he didn't specify 'Tea' then the Earl Grey himself would
   materialise on the tray. How many 18th century English noblemen
   were brought into existence before Jean-Luc worked that one out.

Lance Parkin
 ------

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

Search



Quick Links

User menu

Not signed in.

Misc Menu