Iñaki Baz Castillo | 1 Jul 2008 01:43
Gravatar

Re: Ruby good-practice

El Martes, 1 de Julio de 2008, Justin To escribió:
> Thanks, very helpful. How about using 'begin...rescue...ensure...end'.
> Should I use this everywhere in my code and for every program I do? Or
> is this only for debugging?

Some methods don't return "false" when they fail (for example read IO class). 
But they generate exceptions (different exceptions for each kind of failure).

For example, if you are handling a TCP connection and try to send a message, 
if it fails you'd like to know the cause:
  - TCP connection closed.
  - ICMP error.
  - ...

Maybe TCPSocket#puts method return a different exception in case of failure 
for the above cases (is just an example), and this info can be very useful 
for you.

So, sometimes is more useful to match exceptions instead of getting the return 
value of a method.

Regards.

--

-- 
Iñaki Baz Castillo


Gmane