Using exceptions on all of my controller actions

Hello guys, I was wondering how good is it to use exceptions for
everything in your rails application.

I mean like using save! everytime instead of the plain save. Or using
begin and rescue in every action in your controller.

Is this adviseable? does it hit the application on the performance side?
Is it better to avoid them and use them just when really necessary?

I will appreciate any comments you may have on this. Thanks in advance.

Ok, here is a little example to make things clearer:

This is the ordinary form:
def update
@user = User.find( params[ :id ] )
if @user.update_attributes( params[ :user ] )
flash[ :notice ] = ‘User was successfully updated.’
redirect_to :action => ‘list’
else
render :action => ‘edit’
end
end

This is the form I prefer, but I don’t know if I’m paying an excesive
price using exceptions instead of simple if’s.
def update
begin
@user = User.find( params[ :id ] )
@old_name = @user.login
@user.update_attributes!( params[ :user ] )
flash[ :notice ] = update_ok( @user.login )
redirect_to :action => ‘list’
rescue ActiveRecord::RecordNotFound => e
flash[ :error ] = find_error
redirect_to :action => ‘list’
rescue => e
flash[ :error ] = update_error( @old_name )
render :action => ‘edit’
end
end

What do you think?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs