Move the autodie exception code into its own function.

This is a very simple extraction.

For #9