database: Catch elf_exception locally and log it

Bubbling up th exception terminates the COPY operation with an error,
which aborts the transaction, causing logging the error in the
database to fail.