[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Class Library Exception Passing To Other Class Library Or Executable?

Posted on 2012-12-22
6
Medium Priority
?
367 Views
Last Modified: 2012-12-27
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();
        }
0
Comment
Question by:pointeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 18

Accepted Solution

by:
Gary Davis earned 2000 total points
ID: 38715724
Since your dll is doing a throw, your call to msgQueue will need a try/catch to know the details of the exception being thrown.

Another alternative is to have an Error property within the MessageQueue class and that would have to be set with the error information if an error occurs instead of issuing a throw. Then you will need to test the Error property at various points and act as needed.

Gary Davis
0
 

Author Comment

by:pointeman
ID: 38715761
Q. Do you think the .dll 'Catch' is correct or do you recommend another way?
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 38716052
The try/catch in the dll looks correct to me.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pointeman
ID: 38716084
Q. Do you prefer throw ex; vs my code example?

I've also been working with throw ex.Innexcepion; as well.
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 38716224
I'm not sure I understand. Your example does issue a throw.
0
 

Author Closing Comment

by:pointeman
ID: 38725618
Thx
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question