[rspec-users] Question on SQL exceptions
tim at pivotib.com
Mon Mar 9 17:22:03 EDT 2009
>> ActiveRecord doesn't know anything about db constraint errors. If
>> is violated, the error propagates up in the form of an exception.
> I realize that, but the exception is of the
> ActiveRecord:StatementInvalid class, which I should be able to catch
> the controller with a rescue clause. But, I am not getting this to
> at the moment. I thought that this should at least produce some out
> but it never does:
> def create
> @entity = Entity.new(params[:entity])
> respond_to do |format|
> rescue => my_exception
> puts "Rescue clause invoked!"
> puts my_exception
> For now, all I want is to see the rescue clause invoked, but it is
> have I put this clause in the wrong place? Am I specifying it wrong?
Just a stab in the dark, but I haven't seen any mention of calling
save vs. save!. save just puts any errors in the model, save! will
raise the exception if there are any errors. That may not be the case
for ActiveRecord:StatementInvalid exception, but I thought i'd mention
More information about the rspec-users