Improving exception handling for filters

The patch adds tests for #812 and handles exceptions in after filters.