Currently, this will break instance variable assignment -- not the @after var - it will not make it into the view, as assigns are set in the first render_to_string and never reset due to the exception.
def render_to_string_with_caught_exception
@before = "i'm before the render"
begin
render_to_string :file => "not found!!", :use_full_path => true
rescue
end
@after = "i'm after the render" # this will never make it into @assigns
render :action => "test/hello_world"
end
The use case that turned this up was where I was using render_to_string to load in some static html that corresponded to most of my users, but in a few cases we wouldn't have a matching file for new users. So I specifically rescued the MissingTemplate exception, but my processing I had after the render_to_string was useless as the results never made it to the view.
I've attached a patch with tests that just wraps the render_to_string call in a rescue block, and ensures that things are cleaned up after the render call even if we get an exception.
I also threw in a test case showing that render_to_string followed by a normal render does NOT throw a DoubleRender error, just to make that one specification clear in the code.