Question:
How is message handling implemented in Mathematica when applying Set to unprotected global variables such as $TimeZone in the System context?
Exercise:
The documentation indicates that Set can be used with arguments such as Integer, Real, or a time zone String (e.g. "Asia/Hong_Kong"), and so if I set $TimeZone to something I know not to exist such as $TimeZone = "America/Agloe" or anything not supported for that matter, I receive the following message:
I suspect this functionality has been implemented using a low-level or undocumented version of something similar to $Pre or its close cousin $PreRead. As these are both also global variables defined in the System context it appears this functionality is not implemented using them.
Problem Motivating the Question:
I would like to implement in one of my own packages a similar behavior for some exported global variables that will hold package settings as state variables but without having to define one or more setGlobalVariable[...] functions and avoiding protecting these global variables. This would more easily open up the possibilty to override these global variables with the Block[{$MyGlobalVariable = MySettingForGlobalVariable},...] construct.


MessageandMessageNamein the Documentation Center. Also, see this answer for an example of how these functions are used. – m_goldberg Nov 18 '15 at 05:18