class GlobalExceptionVariables
A RuboCop cop that warns against using global exception variables.
This cop discourages the use of:
$!(last exception)$@(backtrace of last exception)$ERROR_INFO(English name for$!)$ERROR_POSITION(English name for$@)
These global variables are implicit and can make code harder to understand. Instead, use explicit exception handling with rescue blocks and local variables.
good
begin risky_operation rescue => error puts error.message puts error.backtrace.first end
Example.
# bad
begin
risky_operation
rescue
puts $!.message
puts $@.first
end