Fix exception handling in print_expression()

This turned out to be a lot trickier than I thought, but hopefully
I managed to fix all the cases.  It doesn't help that how this is
supposed to be done is pretty much entirely undocumented. :-(