check if last opened file exists before opening it

This should fix #916.