-
Notifications
You must be signed in to change notification settings - Fork 818
Closed
Description
I tried to inspect and get backtrace of exceptions in C
and I noticed that backtrace
returns an empty array after inspect
is called.
#include <stdio.h>
#include <mruby.h>
#include <mruby/compile.h>
#include <mruby/string.h>
mrb_value mrb_get_backtrace(mrb_state *mrb, mrb_value self);
int main(void)
{
mrb_state *mrb = mrb_open();
mrbc_context *context = mrbc_context_new(mrb);
mrbc_filename(mrb, context, "file");
mrb_load_string_cxt(mrb,
"def foo\n"
" xxx(0)\n"
"end\n"
"foo",
context);
mrb_value exc = mrb_obj_value(mrb->exc);
// this works //
mrb_value backtrace = mrb_get_backtrace(mrb, exc);
puts(mrb_str_to_cstr(mrb, mrb_inspect(mrb, backtrace)));
// => ["file:2:in Object.foo", "file:4"]
mrb_value inspect = mrb_inspect(mrb, exc);
puts(mrb_str_to_cstr(mrb, inspect));
// this does not works //
/*
mrb_value inspect = mrb_inspect(mrb, exc);
puts(mrb_str_to_cstr(mrb, inspect));
mrb_value backtrace = mrb_get_backtrace(mrb, exc);
puts(mrb_str_to_cstr(mrb, mrb_inspect(mrb, backtrace)));
// => []
*/
mrbc_context_free(mrb, context);
mrb_close(mrb);
return 0;
}
The same thing works fine when I loaded this file in mruby
command.
begin
5.times do
raise "error"
end
rescue => exc
p exc.inspect
p exc.backtrace
end
Metadata
Metadata
Assignees
Labels
No labels