Revised error handling

Return -1 if any exception is caught.