#915 – An Exception Can Cross Assembly Boundaries

If code within one assembly calls code within another assembly, exceptions originating within the code being called can bubble up to the calling code.  The exception can be thrown from one assembly and caught in another.

Below, code in the ConsoleApplication1 assembly calls code in the DogLibrary assembly (the Dog.Bark method).  When an exception originates in DogLibrary, we can catch it in the code running in ConsoleApplication1.


Code in ConsoleApplication1:

                Dog d = new Dog("Bowser");
            catch (ApplicationException exc)

Code in DogLibrary:

    public class Dog
        public string Name { get; set; }

        public Dog(string name)
            Name = name;

        public void Bark(int numTimes)
            if (numTimes > 10)
                throw new ApplicationException("Too many times to bark");

            for (int i = 0; i < numTimes; i++)

Catching an exception in ConsoleApplication1 that was thrown from DogLibrary:

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

One Response to #915 – An Exception Can Cross Assembly Boundaries

  1. Pingback: #916 – Exception Can Cross .NET Language Boundaries | 2,000 Things You Should Know About C#

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 )

Connecting to %s

%d bloggers like this: