Rethrow exception without slicing. Fixes #6036.

Maybe it should use `catch(...)`, that's what iostreams uses everywhere else.