use temporary files and catch exceptions