ToddT
ToddT

Reputation: 3258

Is it possible for begin .. rescue to NOT catch an exception?

I have a process that is within a begin rescue loop, that looks like this:

begin
  # do some stuff
rescue Exception => e
  Rails.logger.info "#{e.response.message}"
end

Is it possible for this to NOT catch an exception? For some reason my process is running, not throwing errors, but randomly not working.

Upvotes: 1

Views: 1143

Answers (2)

Eric Duminil
Eric Duminil

Reputation: 54243

Just use :

# do some stuff

without any begin/rescue block, and see which Error comes out. Let's say it is NoMethodError. Maybe you have a typo in some of your code, like "abc".spilt. Correct it. Try again, maybe you get Errno::ECONNRESET.

Try :

begin
  # do some stuff
rescue Errno::ECONNRESET => e
  Rails.logger.info "#{e.message}"
end

Rinse and repeat, but start from scratch. rescue Exception is just too much.

Upvotes: 1

sig
sig

Reputation: 392

Maybe you can temporary comment rescue block:

#begin
  ...
#rescue Exception => e
 #Rails.logger.info "#{e.response.message}"

or you can raise raise this exception in rescue:

begin
  do some stuff
rescue Exception => e
  Rails.logger.info "#{e.response.message}"
  raise e
end

Upvotes: 0

Related Questions