Project

General

Profile

Feature #14141 ยป 0002-Add-Exception-display-to-log-exception.patch

sorah (Sorah Fukumori), 11/30/2017 10:12 AM

View differences:

NEWS
34 34
* Exception
35 35

  
36 36
  * Exception#formatted  [Feature #14141]
37
  * Exception#display  [Feature #14141]
37 38

  
38 39
* Dir
39 40

  
error.c
938 938

  
939 939
/*
940 940
 * call-seq:
941
 *   exception.display(port=$stderr) -> nil
942
 *
943
 * Prints formatted <i>exception</i> on the given port (default to <code>$stderr</code>).
944
 * Format includes backtrace, exception class and exception message.
945
 *
946
 * This method is useful to log caught exceptions.
947
 *
948
 *     begin
949
 *       some_work
950
 *     rescue => e
951
 *       e.display
952
 *       retry
953
 *     end
954
 */
955

  
956
static VALUE
957
exc_display(int argc, VALUE *argv, VALUE exc)
958
{
959
    VALUE str = rb_str_new2("");
960
    VALUE out;
961

  
962
    if (argc == 0) {
963
        out = rb_stderr;
964
    }
965
    else {
966
        rb_scan_args(argc, argv, "01", &out);
967
    }
968

  
969
    rb_ec_error_write(exc, Qundef, str);
970
    rb_io_write(out, str);
971

  
972
    return Qnil;
973
}
974

  
975
/*
976
 * call-seq:
941 977
 *   exception.message   ->  string
942 978
 *
943 979
 * Returns the result of invoking <code>exception.to_s</code>.
......
2199 2235
    rb_define_method(rb_eException, "==", exc_equal, 1);
2200 2236
    rb_define_method(rb_eException, "to_s", exc_to_s, 0);
2201 2237
    rb_define_method(rb_eException, "formatted", exc_formatted, 0);
2238
    rb_define_method(rb_eException, "display", exc_display, -1);
2202 2239

  
2203 2240
    rb_define_method(rb_eException, "message", exc_message, 0);
2204 2241
    rb_define_method(rb_eException, "inspect", exc_inspect, 0);
2205
-