るりまサーチ

最速Rubyリファレンスマニュアル検索!
44件ヒット [1-44件を表示] (0.133秒)

別のキーワード

  1. string b
  2. _builtin b
  3. b
  4. b _builtin

ライブラリ

キーワード

検索結果

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

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

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

//emlist[例][ruby]{
b
egin
b
egin
raise "inner"
rescue
raise "outer"
end
rescue
$!.backtrace # => ["/path/to/test.rb:5:in `rescue in <main>'", "/path/to/test.rb:2:in `<main>'"]
$!.set_backtrace(["d...
...ummy1", "dummy2"])
$!.backtrace # => ["dummy1", "dummy2"]
end
//}...

Exception#backtrace -> [String] (6209.0)

バックトレース情報を返します。

...)
* "#{sourcefile}:#{sourceline}"
(トップレベルの場合)

という形式の String の配列です。

//emlist[例][ruby]{
def methd
raise
end

b
egin
methd
rescue => e
p e.backtrace
end

#=> ["filename.rb:2:in `methd'", "filename.rb:6"]
//}

@see Exception#backtrace_locations...

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

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

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

返される文字列は Ruby が捕捉されなかった例外を標準エラー出力に出力するときと
同じ形式です。
そのため、メソッド呼び出し時に $stderr が変更されておらず、$stderr.tty? が真の場合...
...値は Exception.to_tty? の返り値と同じです。

@param order :top か :bottom で指定する必要があります。
バックトレースの一番奥がエラーメッセージの上(top)か下(bottom)かを指定します。
デフォルト値は Exception.to_tt...
...ら :bottom で偽なら :top です。

//emlist[例][ruby]{
b
egin
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 `<...

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

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

...ds::Hash#to_json に渡されます。

//emlist[例][ruby]{
require "json/add/core"

b
egin
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::Gener...