Check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html/secure01142004.asp David LeBlanc introduces a SafeInt template class that throws exceptions whenever integer overflow occurs.