Variáveis ​​globais excepcionais

  • $! – contém a exceção passada para o bloco de resgate
  • $ @ – contém o chamador da exceção ou rastreamento de pilha

Exemplos:

exception = 0/0 rescue $! # returns the exception 
# that would have been raised

puts exception
# prints "divided by zero"
puts exception
.message # prints "divided by zero"
puts exception
.class # prints "ZeroDivisionError"
puts exception
.backtrace # prints the backtrace


trace
= 0/0 rescue $@ # trace is an array
puts trace
# prints out the backtrace