[rspec-users] Question on SQL exceptions
scott at railsnewbie.com
Mon Mar 9 16:59:33 EDT 2009
On Mar 9, 2009, at 4:53 PM, James Byrne wrote:
> Pat Maddox wrote:
>> 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?
You can try "rescue Exception" which rescues from all exceptions, not
just ones which inherit from StandardError. (rescue without an
explicit error class *only* rescues from StandardExceptions and error
classes which derive from it):
Also - I believe this only works in 1.8.6 and above, so if you're
still on 1.8.5 I'd recommend an upgrade.
> Posted via http://www.ruby-forum.com/.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users