Skip to main content

Posts

Showing posts from May, 2012

Reasons Not to Mess with Children

A  little girl was talking to her teacher about whales.   The teacher said it was physically impossible for a whale to swallow  a human because even though it was a very large mammal its  throat was very small. The little girl stated that Jonah was swallowed by a whale. Irritated, the teacher reiterated that a whale could not swallow  a human; it was physically impossible.  The little girl said, 'When I get to heaven I will ask Jonah.' The teacher asked, 'What if Jonah went to hell?' The little girl replied, 'Then you ask him.'     A  Kindergarten teacher was observing her classroom of children  while they were drawing. She would occasionally walk around  to see each child's work. As she got to one little girl who was working diligently,  she asked what the drawing was. The girl replied, 'I'm drawing God.'   The teacher paused and said,  'But no one knows what God looks like.' Without missing a beat, or looking up from her

Catching Unhandled Exceptions [C#]

This example shows how to manage all exceptions that haven't been caught in the try-catch sections (in Windows Forms application). The  UnhandledException event  handles uncaught exceptions thrown from the main UI thread. The  ThreadException event  handles uncaught exceptions thrown from non-UI threads. [C#] static void Main() { Application .EnableVisualStyles(); Application .SetCompatibleTextRenderingDefault( false ); Application . ThreadException += new ThreadExceptionEventHandler (Application_ThreadException); AppDomain .CurrentDomain. UnhandledException += new UnhandledExceptionEventHandler (CurrentDomain_UnhandledException); Application .Run( new Form1 ()); } static void Application_ThreadException( object sender, ThreadExceptionEventArgs e) { MessageBox .Show(e.Exception.Message, "Unhandled Thread Exception" ); // here you can log the exception ... } static void CurrentDomain_UnhandledException( object sender, UnhandledException