Index: core/impl/main/java/org/directwebremoting/engine.js =================================================================== --- core/impl/main/java/org/directwebremoting/engine.js (revision 2132) +++ core/impl/main/java/org/directwebremoting/engine.js (working copy) @@ -23,6 +23,19 @@ (function() { dwr.engine = { }; + + dwr.engine._exceptionHandlers = { }; + + /** + * Register an exception handler for {@code type} + * @param type The type of exception to match. This can be a constructor value + * or class name + * @param {Function} handler The function to call when an exception occurs happens + * @see http://getahead.org/dwr/browser/engine/errors + */ + dwr.engine.registerExceptionHandler = function(type, handler) { + dwr.engine._exceptionHandlers[type] = handler; + }; /** * Set an alternative error handler from the default alert box. @@ -688,14 +701,39 @@ if (ex.message == undefined) { ex.message = ""; } - + + var chain = true; if (typeof handlers.exceptionHandler == "function") { - handlers.exceptionHandler.call(handlers.exceptionScope, ex.message, ex, handlers.exceptionArgs); + chain = handlers.exceptionHandler.call(handlers.exceptionScope, ex.message, ex, handlers.exceptionArgs); } - else if (typeof batch.errorHandler == "function") { - batch.errorHandler(ex.message, ex); + + var registeredHandler = dwr.engine.remote.getRegisteredExceptionHandler(ex); + if (chain && typeof registeredHandler == 'function') { + chain = registeredHandler.call(Object, ex.message, ex); } + else if (chain && typeof batch.errorHandler == "function") { + chain = batch.errorHandler(ex.message, ex); + } }, + + /** + * Called by the handleException: Find a global exception handler + * for the given exception + * @private + * @param {Object} ex Exception instance + * @return Registered exception handler or undefined if there is no handler registered for {@code ex} + */ + getRegisteredExceptionHandler: function(ex) { + for (var type in dwr.engine._exceptionHandlers) { + // Use coercion (==) operator to compare functions + if (type == ex.constructor) { + return dwr.engine._exceptionHandlers[type]; + } + else if (ex.javaClassName && ex.javaClassName === type) { + return dwr.engine._exceptionHandlers[type]; + } + } + }, /** * Called by the server: The whole batch is broken