From: Sean Chittenden Date: 2002-09-14T03:30:51+09:00 Subject: Re: Disabling exceptions - thoughts? > |On #ruby-lang tonight, the topic of disabling exceptions came up. In Perl, > |for example, you can temporarily (or permanately) disable particular (or all) > |warnings via a "no warnings" pragma. I'm told CommonLisp also has something > |along these lines. > | > |Ignoring the "is it wise" for the moment, is it *possible* to disable > |exceptions in Ruby? > > Not in the current implementation. Besides we should define first > what is going to happen on exceptional situation when exception is > turned off. You mean if the exception isn't being ignored? It should be raised as a normal exception would and left to the current stack. You mean something like a different exception or a possible bug? Here's some broken pseudo code that doesn't actually work, but illustrates the idea: Errno::EEXISTS.ignore do Dir.mkdir('/usr') Dir.mkdir('/usr/ports') Dir.mkdir('/usr/ports/databases') Dir.mkdir('/usr/ports/databases/postgresql-devel') end I know there are work arounds, but writing: begin Dir.mkdir('/usr') rescue Errno::EEXISTS end begin Dir.mkdir('/usr/ports') rescue Errno::EEXISTS end etc... gets tedious. I know that in CL you can turn specific exceptions off (thx matju) and that there are other ways to code this, but in short hack scripts that system admins use/write, it's pretty nice to be able to just disregard a specific exception. Here's some more broken code to try and illustrate the idea: class Exception def Exception.ignore(reraise_count = nil, &proc) exception_count = reraise_count.to_i begin yield(proc) rescue self.class exception_count -= 1 if exception_count.kind_of? Fixnum if reraise_count.nil? or reraise_count != 0 # This implies that a proc object knows what instruction the # proc object left off on proc.resume() end end # begin end # def Exception.ignore() end # class Exception Just an idea. -sc -- Sean Chittenden