Avatar of pointeman
pointeman
Flag for United States of America asked on

Class Library Exception Passing To Other Class Library Or Executable?

I want to learn the absolute correct way to pass exceptions from Class Library .dll to other .dll or Executable (Form1). I don't receive the actual .dll exception, instead I receive a general try/catch exception from the Form1 attempt to use the .dll. Help!

[Example Summary]
Click a button on Form1 to clear the local Queue without first specifying the Queue name will cause an exception.
Seems to me the the .dll CreateQueue() exception should 'bubble-up' to Form1.

Does this make sense?

Q1. How do I pass the .dll exception to the .exe (MyForm1)?
Q2. How do I pass the .dll exception to another .dll then to .exe (MyForm1)?

[MyForm1.exe]
public static void ClearQueue()
        {
            msgQueue.QueueName = ""; //intentionally blank for testing purposes
            msgQueue.ClearQueue();
        }


[MyQueueManager.dll] (referenced by MyForm1.exe)
        public static void CreateQueue()
        {
            try
            {
                if (MessageQueue.Exists(_queueName))
                    msgQueue = new MessageQueue(_queueName);
                else
                    msgQueue = MessageQueue.Create(_queueName);
            }
            catch (MessageQueueException ex)
            {
                throw new Exception("MsmqManager.MSMQueue.CreateQueue() Exception: ", ex);
            }
        }

        public static void ClearQueue()
        {
            CreateQueue();

            msgQueue.Purge();
        }
C#

Avatar of undefined
Last Comment
pointeman

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gary Davis

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
pointeman

ASKER
Q. Do you think the .dll 'Catch' is correct or do you recommend another way?
Gary Davis

The try/catch in the dll looks correct to me.
pointeman

ASKER
Q. Do you prefer throw ex; vs my code example?

I've also been working with throw ex.Innexcepion; as well.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Gary Davis

I'm not sure I understand. Your example does issue a throw.
pointeman

ASKER
Thx