on quit event or something like that

I’ve build an applescript App that stays open and keeps checking some condition, I’d like it to ask me the user password if i try to quit it, or run some code when i quit it. but can’t seem to find an option like that
is it possible? or must i have another app that check if the first gets closed to run the code(that would be awful)?

Thanks to everyone and sorry for the poor english

Straight from the AppleScript Language Guide: