Error handling

Write error message to stderr. Terminate process with specified code on failure.