File handling and exceptions