I am using Jinja2 (2.8) under Python (3.4) with Tornado (4.3), and things 
work well--except I am having trouble catching exceptions that Jinja2 
raises.

For example, I will do something like this:

                try:
                    buf = template.render(data=this_data)
                except Exception as e:
                    buf = '<html><body>Error rendering 
template.</body></html>'

However when an exception is raised by Jinja2 while rendering, it is not 
caught by the except block.  Instead, the exception bubbles up with a 
traceback like this:

Can't convert 'NoneType' object to str implicitly

['Traceback (most recent call last):\n', ' File "C:/Projects/OsPy/OsPy.py", 
line 1020, in background_process_post_authenticated\n buf = 
template.render(data=this_data)\n', ' File 
"C:\\Prog\\Python34\\lib\\site-packages\\jinja2\\environment.py", line 989, 
in render\n return self.environment.handle_exception(exc_info, True)\n', ' 
File "C:\\Prog\\Python34\\lib\\site-packages\\jinja2\\environment.py", line 
754, in handle_exception\n reraise(exc_type, exc_value, tb)\n', ' File 
"C:\\Prog\\Python34\\lib\\site-packages\\jinja2\\_compat.py", line 37, in 
reraise\n raise value.with_traceback(tb)\n', ' File "


I suspect that this has to do with the fact that I am using Tornado with 
asynchronous execution and background threads (i.e. using 
@tornado.gen.coroutine and @run_on_executor decorators), and handling the 
exception with a future needs to be done differently.  But I am new to all 
of this...and am wondering if anyone has some suggestions.

Is anyone here using Jinja2 with Tornado and successfully trapping 
exceptions?

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pocoo-libs+unsubscr...@googlegroups.com.
To post to this group, send email to pocoo-libs@googlegroups.com.
Visit this group at https://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.

Reply via email to