Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method · added in Ruby 3.2

Exception#detailed_message

(?highlight: bool?, **untyped ignored) -> ::String
detailed_message(highlight: false, **kwargs) → string

Returns the message string with enhancements:

  • Includes the exception class name in the first line.

  • If the value of keyword highlight is true, includes bolding and underlining ANSI codes (see below) to enhance the appearance of the message.

Examples:

Example
begin
  1 / 0
rescue => x
  p x.message
  p x.detailed_message                  # Class name added.
  p x.detailed_message(highlight: true) # Class name, bolding, and underlining added.
end

Output:

Example
"divided by 0"
"divided by 0 (ZeroDivisionError)"
"\e[1mdivided by 0 (\e[1;4mZeroDivisionError\e[m\e[1m)\e[m"

This method is overridden by some gems in the Ruby standard library to add information:

An overriding method must be tolerant of passed keyword arguments, which may include (but may not be limited to):

  • :highlight.

  • :did_you_mean.

  • :error_highlight.

  • :syntax_suggest.

An overriding method should also be careful with ANSI code enhancements; see Messages.

Ruby version changes

  1. 3.2