Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the list of the types of exceptions?

Please help me find the official documentation with a list of the types of of exceptions. I wrote this action:

def show
  begin
    @user = User.find(params[:id])   
  rescue ActiveRecord::RecordNotFound => e
    logger.debug e
    logger.debug "Error #{$!}"
    render_404      
  end
end

I need to mention several types of exceptions:

def show
  begin
    @user = User.find(params[:id])   
  rescue ActiveRecord::RecordNotFound => e
    logger.debug e
    logger.debug "Error #{$!}"
    render_404  
  rescue anotherExceptionType1 => e   
    ......
    ......
    ..... 
  rescue anotherExceptionType2 => e   
    ......
    ......
    ..... 
  rescue anotherExceptionType3 => e   
    ......
    ......
    .....         
  end
end

but I did not find the list of exceptions in the documentation.

like image 754
stackov8 Avatar asked Nov 28 '22 16:11

stackov8


2 Answers

You can see all the subclasses of ActiveRecordError here: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/errors.rb

like image 162
Maxim Pontyushenko Avatar answered Dec 08 '22 00:12

Maxim Pontyushenko


I can give you a list of exceptions but I am not sure if that is what you really want. Instead you probably want to figure out which exceptions will be thrown in your specific case. More importantly you probably should not be rescuing exceptions to begin with. For more information take a look at this link

However you asked for a list so here you go:

  • Exception
  • NoMemoryError
  • ScriptError
  • LoadError
  • NotImplementedError
  • SyntaxError
  • SignalException
  • Interrupt
  • StandardError
  • ArgumentError
  • IOError
  • EOFError
  • IndexError
  • LocalJumpError
  • NameError
  • NoMethodError
  • RangeError
  • FloatDomainError
  • RegexpError
  • RuntimeError
  • SecurityError
  • SystemCallError
  • SystemStackError
  • ThreadError
  • TypeError
  • ZeroDivisionError
  • SystemExit
  • fatal

You can visit the link to find a hierarchy of the errors as well.

like image 26
2016rshah Avatar answered Dec 08 '22 00:12

2016rshah