Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

SyntaxSuggest.handle_error

handle_error(e, re_raise: true, io: $stderr)

Takes a SyntaxError exception, uses the error message to locate the file. Then the file will be analyzed to find the location of the syntax error and emit that location to stderr.

Example:

Example
begin
  require 'bad_file'
rescue => e
  SyntaxSuggest.handle_error(e)
end

By default it will re-raise the exception unless ‘re_raise: false`. The message output location can be configured using the `io: $stderr` input.

If a valid filename cannot be determined, the original exception will be re-raised (even with ‘re_raise: false`).

See also #detailed_message also in 4.0 · 3.4 · 3.3 · 3.2