Python: Check if file was saved
If 'the file' you are referencing is a blender file and you want to know if it has been saved then there are two properties you can check.

If a blender file hasn't been saved at all you can check it's is_saved property as this will be False if it hasn't been saved:

if bpy.data.is_saved:
    #File has been saved. Do something.


(A previous version of this answer instead checked if the filepath property was blank instead - the above is a correction thanks to poor's comment).

For files that have been saved you can check the is_dirty property, which will be True when changes have been made since the last save:

if bpy.data.is_dirty:
    #Changes have been made since the last save. Do something.


To get a button to execute code have a look at Simple way to add button to UI.

For error messages look at Proper way to show users error info in the UI for addons.