Why only do the cleanup on this error?  Also, files should automatically close on garbage collection.  Also, if the exception is the only expected error, you can do the cleanup before raising the exception and get rid of the try block.  And again, you should use a proper exception class.