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

.



Relevant Pages

  • Re: Thread Pre-Emption Question . . .
    ... Not checking for failure of InitializeCriticalSection, ... not checking deallocateor failure is okay because the program will continue to run correctly although it is good practice to check this in debug builds because deallocators usually only fail because of invalid arguments. ... the correct execution of error handling logic (if the access causes unplanned exceptions before data corruption and these unplanned exceptions are caught in the same place as planned exceptions for example). ... This can, and will, corrupt real data in any number of random ways depending on the work done in the writer. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Thread Pre-Emption Question . . .
    ... Not checking for failure of InitializeCriticalSection, ... not checking deallocateor failure is okay because the program will continue to run correctly although it is good practice to check this in debug builds because deallocators usually only fail because of invalid arguments. ... correct execution of error handling logic (if the access causes unplanned exceptions before data corruption and these unplanned exceptions are caught in the same place as planned exceptions for example). ... This can, and will, corrupt real data in any number of random ways depending on the work done in the writer. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: required attribute "ALT" not specified .
    ... what is the simple logic I fail to ... "iMacs are good" is wrong. ... be uncategorically hypocritical to make personal exceptions. ... I take everything you say with the utmost seriousness. ...
    (alt.html)
  • Re: Thread Pre-Emption Question . . .
    ... Specific bugs: ... handler to catch it and it will be very difficult to construct to fail ... that do not raise exceptions on failure so their return codes must be ... this could allow a reader and writer to access the data concurrently. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Argument Checking
    ... When arguments fail during check, do you return from the call with an ... or do you throw exceptions? ... trying to figure out their bug. ... with even the longest attention spans. ...
    (comp.lang.javascript)