From: Thom Harp Date: 2001-12-15T10:09:28+09:00 Subject: [ruby-talk:28568] Blocking exceptions I think it would be useful if there was a shorthand way to say you want to ignore a certain type of exception over a method call. For example, I call waitpid in a loop in my SIGCHLD handler to clean up any pending children. If there are no children and you specified the WNOHANG flag, waitpid returns 0 (and sets errno to ECHILD). Since it's not necessarily an error for errno to be set in this situation I'd like to block it so that if it's raise inside waitpid, I never see it - waitpid just returns 0. Here's the long way that I have to do it now: trap('SIGCHLD') do loop do begin pid = Process.waitpid(-1,Process::WNOHANG) rescue Errno::ECHILD break end end end I'd like it to look more like this: trap('SIGCHLD') do while( (pid = Process.waitpid(-1,Process::WNOHANG))) end end We'd need some more syntax to indicate that I want to ignore that exception, like maybe declare a block so that if a certain exception is raised from a function called within that block, control resumes normally where that function would have returned to the block, like: trap('SIGCHLD') do ignore(Errno::ECHILD) do while( (pid = Process.waitpid(-1,Process::WNOHANG))) end end end Or is there a way I could code this in Ruby? -thom