Issue of using Static Methods calls and Unhandled Exceptions

Recently one of my fellow developer had an issue of application crashing after making a new change.

Application keeps crashing and errors are not getting logged

While checking the Event Viewer found the following details

Event Type:      Error

Event Source:   .NET Runtime 2.0 Error Reporting

Event Category:            None

Event ID:          5000

Date:                4/18/2011

Time:                12:52:55 PM

User:                N/A

Computer:         XXXXX


EventType clr20r3, P1 dataprocess.exe, P2, P3 4da27055, P4 dataprocess, P5, P6 4da27055, P7 30, P8 b, P9 system.typeinitialization, P10 NIL.

Developer spent almost more than 5 hours to troubleshoot the problem.

Finally issue was due to the Static calls

public partial class Form1 : Form
  public static String _email_DevTeam = Configuration.GetValue("Email_DevTeam").ToString();   public static String _email_SentFrom = Configuration.GetValue("Email_SentFrom").ToString();   public static String _smtp = Configuration.GetValue("smtp").ToString();

Configuration.GetValue method didn’t had Exception handling and since Static calls being made before constructor or Form_Load() Event, Exception handling code in Form didn’t work.

Developers, Beware of using Static Functions !!!

Make sure all methods are having exception handling !!!

%d bloggers like this: