Issue #12026 has been updated by Jeremy Evans.


Tsuyoshi Sawada wrote:
> Can we have additional syntax that is analogous to `rescue` (but a little different)? Maybe something that takes a regex (instead of exception class) for matching, and an optional `=>` that assigns `message` (and possibly `backtrace`):
> 
> ~~~RUBY
> begin
>   some_routine
> catch_warning /some regex pattern to match a warning/ => message, backtrace
>   # do whatever with message, backtrace
> end
> # continues
> ~~~
> 
> Note that, unlike `rescue`, catching a warning should not affect the code flow following the block; it only absorbs the warning message.

If you would like ruby to support that, please open a new feature request for it.  I don't want to derail the discussion of this feature request with your proposal.

----------------------------------------
Feature #12026: Support warning filters
https://bugs.ruby-lang.org/issues/12026#change-57605

* Author: Jeremy Evans
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This adds a simple way to filter warnings from being displayed. You
just set a $WARNING_FILTER with a regexp, and any warnings that
match the regexp will not be displayed.

I think this is a much simpler approach to filtering warnings than
feature #11588, while allowing the same type of capability.

This is backwards compatible, in that you can set $WARNING_FILTER in
previous versions of ruby without problems.

This should not cause any performance issues, as the regexp matching
isn't done until the warning message is about to be displayed.

It's possible to use something other than a global variable to store
the warning filter, but a global variable was the easiest way to
implement it, it has a global effect, and similar flags such as
$VERBOSE are also global variables, so I think a global variable
makes sense.

---Files--------------------------------
0001-Support-warning-filters.patch (4.12 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>