Short answer
That rescue clause doesn't really make sense. Remove it.
Long answer
That's a very bad code. First of all, the question is: who told you to "add exceptions" and for which purpose?
The code
CustomReport.all
is known to raise an exception only in very special cases. Generally speaking, when the application can't connect to the database. In fact, there are no external user inputs or conditions that may cause the code to naturally fail.
Conversely, this code can fail more frequently
CustomReport.find(params[:id])
because find raises an error if the object is not found, which is definitely a more common case.
If your method crashes for a database error, it's likely the entire application is affected so the rescue management probably makes sense in your global application, not really in that method. There's not that much you can do there to rescue it.
Last but not least, rescuing an exception of class Exception
rescue Exception => e
is considered a code smell in Ruby. In fact, you should rescue only StandardErrors or greater. If you rescue an Exception
class you must be very aware of what it means. System level errors and syntax errors inherits from Exception, so if you rescue an Exception
it's likely that you will hide a lot of potential errors in your code.
But again, even rescuing StandardError
does not make a lot of sense. In fact, we said before that CustomReport.all
could only fail in case of database connection errors. This means that, if you really want to rescue something, you should rescue only database failures there.