Replacing trigger_errors with exceptions