#878 – Unhandled Exceptions in Static Constructors

If any exception is thrown from within a static constructor, a TypeInitializationException will be thrown, with an InnerException set to the original exception that occurred.  If this exception is not caught, the application will be terminated.

    public class Dog
    {
        public static string Motto { get; set; }

        static Dog()
        {
            Motto = "Serve humans and chase balls";
            throw new Exception("Static Dog constructor threw me");
        }
    }

878-001

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #878 – Unhandled Exceptions in Static Constructors

  1. Pingback: Dew Drop – July 2, 2013 (#1,577) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: