added exception handling with output to a logfile.