Prev | Current Page 241 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Doing this avoids a StackOverflowException
inside ListSwap(). It??™s remotely possible that, when calling ListSwap(), the stack could be
running on vapors, and the mere allocation of another stack slot could fail and generate an
exception. So, you should perform that step outside of the confines of the ListSwap method.
Once execution is inside ListSwap(), all the locations are allocated and ready for use.
This technique, when applied liberally in a system that requires rigid stability, will quickly
point out methods that may be too complex and need to be broken up into smaller functional
units. In essence, this idiom amplifies the complexity of a particular method it is applied to.
Therefore, if you find that it becomes unwieldy and difficult to make the method bulletproof,
you should analyze the method and make sure it??™s not trying to do too much work that you
could break up into smaller units.
CHAPTER 8 n EXCEPTION HANDLING 147
Incidentally, you may find it necessary to make swap operations, similar to ListSwap(),
atomic in a multithreaded environment. You could modify ListSwap() to use some sort of
exclusive lock object, such as a mutex or a System.Threading.Monitor object. However, you
may find yourself inadvertently making ListSwap() capable of throwing exceptions, and that
violates the requirements on ListSwap().


Pages:
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
Wczasy nad morzem szafy buchsbaum hotele londyn zakłady bukmacherskie