Implement error handling logic, closes #1.