Solved

Class Library Exception Passing To Other Class Library Or Executable?

Posted on 2012-12-22
6
348 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
  • 3
  • 3
6 Comments
 
LVL 18

Accepted Solution

by:
Gary Davis earned 500 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now