Question: Which is better approach and why.

Answer: 
You should seek out the UI guidelines for the platform you are developing on (search for "human interface guidelines" or "look and feel design guidelines"). If they exist, you should follow them so your app is likely to conform to the user's expectations. For example, Apple has [specific guidelines](http://developer.apple.com/mac/library/documentation/userexperience/conceptual/applehiguidelines/XHIGWindows/XHIGWindows.html#//apple_ref/doc/uid/20000961-BACJGAAI) for what to do in this situation on Mac OS X.

The typical advice for this particular scenario is not to have "Yes" or "No" buttons, but buttons that describe the action they perform. For example, you can display a message box like: "Document a.txt has been modified. Save changes?" with the buttons "Save", "Exit without saving", and "Cancel". This makes it clear to the user what each button will do.
Something else I personally think is important is setting focus to whichever button is the equivalent to cancel. I think a lot of users get accustomed to these kind of prompts and just hit enter without even reading what is on the dialog. When they do this I think in most situations it's better to play it safe and cancel than to commit something.