Iñaki Baz Castillo
6/30/2008 11:43:00 PM
El Martes, 1 de Julio de 2008, Justin To escribi=C3=B3:
> 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=
).=20
But they generate exceptions (different exceptions for each kind of failure=
).
=46or example, if you are handling a TCP connection and try to send a messa=
ge,=20
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=
=20
for the above cases (is just an example), and this info can be very useful=
=20
for you.
So, sometimes is more useful to match exceptions instead of getting the ret=
urn=20
value of a method.
Regards.
=2D-=20
I=C3=B1aki Baz Castillo