Why exactly can't Microsoft Word close if there's a dialogue box open?

I occasionally get the error that Word gives when trying to close a document with another dialogue box open but I've never been able to figure out why it happens.


Because most dialog boxes are considered "modal" which means that control does not pass back to the main program, or calling container, until the dialog itself is closed. This is by design and the programmer has the option to make a window modal or non-modal. Usually, a window is defined to be modal if the main program cannot or should not continue until the opened dialog is dealt-with either through selection (Ok) or aborting (Cancel).


The dialog box might be saying something like:

You have made changes to your document, do you want to save them? (Yes) (No)

There is no obvious right answer here. You may have accidentally corrupted your document (for example, the cat walked over the keyboard) in which case the answer is "No", or you might have spent hours typing in changes in which case the answer is "Yes".

The safest thing for Word to do is is refuse to close until you answer the question.


Because the program is designed this way, to avoid taking action the user might not want.

Usually, a dialog box is displayed when the program needs the user to guide some action. Closing an unsaved document is excellent example: a dialog offers to save the changes, discard the changes or abort closing and return to editing. The program intentionally refuses to close without answering this question because closing will force SOME action to be taken. The program can't decide on it's own to eg. discard recent edit, or on the contrary, overwrite correct version with cat-on-the-keyboard typing.

Even if we consider a dialog that's not related to closing, it usually means that some process is underway, it hadn't completed yet, and the user must decide which way to go. It cannot be "simply aborted", because aborting is also an action that the user might not meant.

It also simplifies design of the program, as it's creators don't have to create "a safe way out" of every function.

Today, most dialogs are not modal in the technical sense (the program remains responsible), but it's still easier to make them modal in a wider sense of logic flow of the program.