问题
I have an exception that is produced at ~20 seperate places. It can be rescued easy and in the same way at every place but thats not dry and eaven a crapy work! I want to rescue this exception at a central position. How can I arrange this?
Its about the ActiveRecord::RecordNonUnique
exception by the way,...
回答1:
What about this ?
def rescue_from_record_non_unique
yield
rescue ActiveRecord::RecordNonUnique
# your code
end
# ...
rescue_from_record_non_unique do
# do something
end
来源:https://stackoverflow.com/questions/8644577/how-to-rescue-exception-central-and-dry