Project

General

Profile

Actions

Feature #18659

open

Create a Binding at the time of an exception and make it available to Rescue

Added by pedz (Perry Smith) almost 2 years ago. Updated almost 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:108061]

Description

When an exception occurs, create a binding or I assume make a reference to the current binding and then add that to the Exception class via (e.g.) a #binding method. This would allow users to have a more global rescue code but would still have access to the variables that were in scope at the time of the exception.

My particular use case is when parsing files -- especially a list of files. The outer loop is for each file. The next inner loop is for each line in the file. At the time of an exception, it would be nice to have access while in the a rescue clause to the file name, line number, current line, and other interesting variables. Adding rescue closes in the inner blocks creates a lot of redundant code.

Updated by Eregon (Benoit Daloze) almost 2 years ago

This would be a huge overhead, so I don't think it's a good idea.
If you need this data, you could just pass it down yourself (e.g., the inner loop could be a block and then you already have access to all variables, or you could pass data like the file as arguments), and that way wouldn't slow down ever other exception.

Actions

Also available in: Atom PDF

Like0
Like0