import functools
import sys
-from tornado.stack_context import ExceptionStackContext
+from tornado.stack_context import ExceptionStackContext, wrap
from tornado.util import raise_exc_info, ArgReplacer
try:
callback, args, kwargs = replacer.replace(future.set_result,
args, kwargs)
if callback is not None:
- future.add_done_callback(callback)
+ future.add_done_callback(wrap(callback))
def handle_error(typ, value, tb):
future.set_exception(value)
future = f()
self.assertEqual(future.result(), 42)
+ def test_error_in_callback(self):
+ self.sync_future(callback=lambda future: 1 / 0)
+ # The exception gets caught by our StackContext and will be re-raised
+ # when we wait.
+ self.assertRaises(ZeroDivisionError, self.wait)
+
# The following series of classes demonstrate and test various styles
# of use, with and without generators and futures.
class CapServer(TCPServer):