Skip to content

Instantly share code, notes, and snippets.

@wudi
Last active April 18, 2017 10:44
Show Gist options
  • Save wudi/b07b080f683db3ec217f49f21e5b23cd to your computer and use it in GitHub Desktop.
Save wudi/b07b080f683db3ec217f49f21e5b23cd to your computer and use it in GitHub Desktop.
throw exception in php extension.
zval ex, info;
zend_class_entry *def_ex = zend_ce_exception, *pdo_ex = zend_ce_exception;
object_init_ex(&ex, pdo_ex);
zend_update_property_string(def_ex, &ex, "message", sizeof("message")-1, message);
zend_update_property_string(def_ex, &ex, "code", sizeof("code")-1, *pdo_err);
array_init(&info);
add_next_index_string(&info, *pdo_err);
add_next_index_long(&info, 0);
zend_update_property(pdo_ex, &ex, "errorInfo", sizeof("errorInfo")-1, &info);
zval_ptr_dtor(&info);
zend_throw_exception_object(&ex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment