Skip to content

Instantly share code, notes, and snippets.

@taf2
Created January 3, 2023 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taf2/c4d4ae88b5aae9bef84e3b24d8ef984a to your computer and use it in GitHub Desktop.
Save taf2/c4d4ae88b5aae9bef84e3b24d8ef984a to your computer and use it in GitHub Desktop.
static VALUE callback_exception(VALUE did_raise, VALUE exception) {
VALUE ret = rb_funcall(exception, rb_intern("message"), 0);
VALUE trace = rb_funcall(exception, rb_intern("backtrace"), 0);
if (RB_TYPE_P(trace, T_ARRAY) && RARRAY_LEN(trace) > 0) {
printf("we got an exception: %s:%d\n", StringValueCStr(ret), RARRAY_LEN(trace));
VALUE sep = rb_str_new_cstr("\n");
VALUE trace_lines = rb_ary_join(trace, sep);
if (RB_TYPE_P(trace_lines, T_STRING)) {
printf("%s\n", StringValueCStr(trace_lines));
} else {
printf("trace is not a string??\n");
}
} else {
printf("we got an exception: %s\nno stack available\n", StringValueCStr(ret));
}
rb_hash_aset(did_raise, rb_easy_hkey("error"), Qtrue);
return exception;
}
VALUE did_raise = rb_hash_new();
rb_rescue(call_status_handler1, callargs, callback_exception, did_raise);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment