るりまサーチ

最速Rubyリファレンスマニュアル検索!
44件ヒット [1-44件を表示] (0.130秒)
トップページ > 種類:インスタンスメソッド[x] > クエリ:@[x] > クエリ:main[x] > クラス:Exception[x]

別のキーワード

  1. _builtin main
  2. main define_method
  3. main public
  4. main private
  5. thread main

ライブラリ

キーワード

検索結果

Exception#full_message(highlight: true, order: :bottom) -> String (38.0)

例外の整形された文字列を返します。

...と order は 2.5.1 で追加されました。

@
param highlight エスケープシーケンスによる文字装飾をつけるかどうかを指定します。
デフォルト値は Exception.to_tty? の返り値と同じです。

@
param order :top か :bottom で指定する必...
...す。
デフォルト値は Exception.to_tty? が真なら :bottom で偽なら :top です。

//emlist[例][ruby]{
begin
raise "test"
rescue => e
p e.full_message # => "\e[1mTraceback \e[m(most recent call last):\ntest.rb:2:in `<main>': \e[1mtest (\e[4;1mRuntimeError\e[m\e[1m)\...
...n\e[m"
$stderr = $stdout
p e.full_message # => "test.rb:2:in `<main>': test (RuntimeError)\n"
$stderr = STDERR
p e.full_message # => "\e[1mTraceback \e[m(most recent call last):\ntest.rb:2:in `<main>': \e[1mtest (\e[4;1mRuntimeError\e[m\e[1m)\n\e[m"
end
//}

@
see Exception.to_tty?...
...による文字装飾がついています。


@
param highlight エスケープシーケンスによる文字装飾をつけるかどうかを指定します。
デフォルト値は Exception.to_tty? の返り値と同じです。

@
param order :top か :bottom で指定する必...

Exception#backtrace_locations -> [Thread::Backtrace::Location] (20.0)

バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。

...バックトレース情報を返します。Exception#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。

現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。

//emlist[例: test.rb][ruby]{
require...
...def get_exception
return begin
yield
rescue => e
e
end
end

e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get_exception'", "test.rb:15:in `<main>'"]
//}

@
see Exception#backtr...

Exception#set_backtrace(errinfo) -> nil | String | [String] (20.0)

バックトレース情報に errinfo を設定し、設定されたバックトレース 情報を返します。

...す。

@
param errinfo nil、String あるいは String の配列のいずれかを指定します。

//emlist[例][ruby]{
begin
begin
raise "inner"
rescue
raise "outer"
end
rescue
$!.backtrace # => ["/path/to/test.rb:5:in `rescue in <main>'", "/path/to/test.rb:2:in `<main>'"]
$!....

Exception#to_json(*args) -> String (20.0)

自身を JSON 形式の文字列に変換して返します。

...

内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。

@
param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡されます。

//emlist[例][ruby]{
require "json/add/core"...
...begin
0/0
rescue => e
e.to_json # => "{\"json_class\":\"ZeroDivisionError\",\"m\":\"divided by 0\",\"b\":[\"/path/to/test.rb:4:in `/'\",\"/path/to/test.rb:4:in `<main>'\"]}"
end
//}

@
see JSON::Generator::GeneratorMethods::Hash#to_json...