summaryrefslogtreecommitdiff
path: root/includes/bootstrap.inc
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-02-17 22:44:52 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-02-17 22:44:52 +0000
commit8d01aeb4287be61195a43305e34f379086914f5d (patch)
tree88ef91e8532ed82085dfa5ce8a854116f891173b /includes/bootstrap.inc
parent8847f4c9a2edcd2f555d6a47b5037c88c671cc3c (diff)
downloadbrdo-8d01aeb4287be61195a43305e34f379086914f5d.tar.gz
brdo-8d01aeb4287be61195a43305e34f379086914f5d.tar.bz2
#710142 by Berdir, moshe weitzman, chx: Handle exceptions in shutdown functions (with tests). Hopefully the last of these weird 'Stack frame in Unknown line 0' errors.
Diffstat (limited to 'includes/bootstrap.inc')
-rw-r--r--includes/bootstrap.inc56
1 files changed, 56 insertions, 0 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 13c912cf4..05a654bf1 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -2644,3 +2644,59 @@ function drupal_is_cli() {
function drupal_placeholder($variables) {
return '<em class="placeholder">' . check_plain($variables['text']) . '</em>';
}
+
+/**
+ *
+ * Register a function for execution on shutdown.
+ *
+ * Wrapper for register_shutdown_function() which catches thrown exceptions
+ * to avoid "Exception thrown without a stack frame in Unknown".
+ *
+ * @param $callback
+ * The shutdown function to register.
+ * @param $parameters
+ * It is possible to pass parameters to the shutdown function by passing
+ * additional parameters.
+ * @return
+ * Array of shutdown functions to be executed.
+ *
+ * @see register_shutdown_function()
+ */
+function &drupal_register_shutdown_function($callback = NULL, $parameters = NULL) {
+ // We cannot use drupal_static() here because the static cache is reset
+ // during batch processing, which breaks batch handling.
+ static $callbacks = array();
+
+ if (isset($callback)) {
+ // Only register the internal shutdown function once.
+ if (empty($callbacks)) {
+ register_shutdown_function('_drupal_shutdown_function');
+ }
+ $args = func_get_args();
+ array_shift($args);
+ // Save callback and arguments
+ $callbacks[] = array('callback' => $callback, 'arguments' => $args);
+ }
+ return $callbacks;
+}
+
+/**
+ * Internal function used to execute registered shutdown functions.
+ */
+function _drupal_shutdown_function() {
+ $callbacks = &drupal_register_shutdown_function();
+
+ try {
+ while (list($key, $callback) = each($callbacks)) {
+ call_user_func_array($callback['callback'], $callback['arguments']);
+ }
+ }
+ catch(Exception $exception) {
+ require_once DRUPAL_ROOT . '/includes/errors.inc';
+ // The theme has already been printed so it doesn't make much sense to use
+ // drupal_exception_handler() because that would display the maintenaince
+ // page below the usual page. For now, just print the error for debugging.
+ // @todo: Improve this.
+ print t('%type: %message in %function (line %line of %file).', _drupal_decode_exception($exception));
+ }
+}