Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

Exception Handling

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sid Price - 18 Oct 2007 00:15 GMT
I have a third party class library (C#) that I am expanding and using with
an application (VB.NET) and I am having trouble catching exceptions in the
application. The class library has an exception handler that it calls:

catch (Exception ex)

{

_sSessionId = null;

objUtils.HandleException("Error: Could not login: " + ex.Message);

return "";

}

The handler then throws an exception (the one my application should catch):

throw new Exception(Environment.NewLine + strMessage);

My application has a typical try/catch block but it does not catch the
thrown exception; here Login is in the class library:

Try

strSessionID = oVR.Login()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

I am pretty new to exception handling so perhaps I am misunderstanding, can
someone point me in the right direction please?

Sid.
sloan - 18 Oct 2007 01:48 GMT
Here is a very good article.

http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx

However, your third party class may be breaking the rules.

I don't see what you're doing wrong though.

try

// do someting

catch (Exception ex)

   MessageBox.Show (ex.Message)

end try

How "robust" or trustworthy is the third party code?
Is is a "big" vendor.  Or something somebody threw together.

>I have a third party class library (C#) that I am expanding and using with
>an application (VB.NET) and I am having trouble catching exceptions in the
[quoted text clipped - 34 lines]
>
> Sid.
Sid Price - 18 Oct 2007 18:40 GMT
Thank you for the Blog URL, interesting reading.

I have the source for the class library and the code clips I included were
directly from that source. What could they be doing wrong?
Basically in a method of the class library on an exception they call an
exception handler, that handler then throws an exception that my application
fails to catch. Looking at a call stack:
   MyApplication ----> Method in Library ---> On an exception it calls an
exception handler ---> throws an exception (not caught by MyApplication.
Is this breaking the rules? Should I change the library to simply throw
exceptions that my application should catch?
Thanks again,
Sid.

> Here is a very good article.
>
[quoted text clipped - 55 lines]
>>
>> Sid.
Alvin Bruney [MVP] - 19 Oct 2007 02:09 GMT
No you shouldn't. Your code should catch the exception. How do you know it
isn't catching the exception? Put a break point inside the handler and run
the application. It should catch.

Signature

Regards,
Alvin Bruney
------------------------------------------------------
Shameless Author Plug
OWC Black Book 2nd Edition
Exclusively on www.lulu.com/owc
$24.99

> Thank you for the Blog URL, interesting reading.
>
[quoted text clipped - 70 lines]
>>>
>>> Sid.
Sid Price - 22 Oct 2007 20:53 GMT
If I put a breakpoint in the handler of the class library it gets hit,
however, a breakpoint where my application should catch the exception thrown
by the handler is never hit.
Sid.

> No you shouldn't. Your code should catch the exception. How do you know it
> isn't catching the exception? Put a break point inside the handler and run
[quoted text clipped - 74 lines]
>>>>
>>>> Sid.
Kevin Spencer - 23 Oct 2007 11:57 GMT
It sounds like something between the exception being thrown in the class
library and the application's use of it is catching the exception.
Therefore, it doesn't bubble up to the application.

Signature

HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

> If I put a breakpoint in the handler of the class library it gets hit,
> however, a breakpoint where my application should catch the exception
[quoted text clipped - 80 lines]
>>>>>
>>>>> Sid.
Sid Price - 23 Oct 2007 15:21 GMT
Kevin,
Thanks for the reply; is it okay that the class library to throw an
exception that is caught with its own handler and then for that handler to
throw another exception for the user to catch? Nested exceptions being
thrown.
Sid.

> It sounds like something between the exception being thrown in the class
> library and the application's use of it is catching the exception.
[quoted text clipped - 84 lines]
>>>>>>
>>>>>> Sid.
Kevin Spencer - 25 Oct 2007 11:31 GMT
Not a problem at all, if used correctly. A class library should throw
exceptions unless it can handle them gracefully. My class libraries include
exception handlers that log the details of the exceptions and then throw
them routinely. The logging is optional, and can be turned off if desired,
but I find it very useful in diagnosing problems.

Signature

HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

> Kevin,
> Thanks for the reply; is it okay that the class library to throw an
[quoted text clipped - 92 lines]
>>>>>>>
>>>>>>> Sid.
Sid Price - 25 Oct 2007 18:52 GMT
What is describe is exactly what I am trying to achieve, if only I could
figure out why my application is not catching the exceptions,
Sid.

> Not a problem at all, if used correctly. A class library should throw
> exceptions unless it can handle them gracefully. My class libraries
[quoted text clipped - 98 lines]
>>>>>>>>
>>>>>>>> Sid.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.