|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Exception Handlingan 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. 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. Show quote "Sid Price" <s**@nowhere.com> wrote in message news:ORoNyOREIHA.5752@TK2MSFTNGP02.phx.gbl... >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. > > > > 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. Show quote "sloan" <sl***@ipass.net> wrote in message news:e4lKKCSEIHA.5360@TK2MSFTNGP03.phx.gbl... > 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. > > > > > "Sid Price" <s**@nowhere.com> wrote in message > news:ORoNyOREIHA.5752@TK2MSFTNGP02.phx.gbl... >>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. >> >> >> >> > > 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. -- Show quoteRegards, Alvin Bruney ------------------------------------------------------ Shameless Author Plug OWC Black Book 2nd Edition Exclusively on www.lulu.com/owc $24.99 "Sid Price" <s**@nowhere.com> wrote in message news:OaFOm4aEIHA.5980@TK2MSFTNGP04.phx.gbl... > 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. > > "sloan" <sl***@ipass.net> wrote in message > news:e4lKKCSEIHA.5360@TK2MSFTNGP03.phx.gbl... >> 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. >> >> >> >> >> "Sid Price" <s**@nowhere.com> wrote in message >> news:ORoNyOREIHA.5752@TK2MSFTNGP02.phx.gbl... >>>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. >>> >>> >>> >>> >> >> > > 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. Show quote "Alvin Bruney [MVP]" <some guy without an email address> wrote in message news:%23hRq6yeEIHA.4140@TK2MSFTNGP03.phx.gbl... > 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. > > -- > Regards, > Alvin Bruney > ------------------------------------------------------ > Shameless Author Plug > OWC Black Book 2nd Edition > Exclusively on www.lulu.com/owc > $24.99 > > > "Sid Price" <s**@nowhere.com> wrote in message > news:OaFOm4aEIHA.5980@TK2MSFTNGP04.phx.gbl... >> 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. >> >> "sloan" <sl***@ipass.net> wrote in message >> news:e4lKKCSEIHA.5360@TK2MSFTNGP03.phx.gbl... >>> 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. >>> >>> >>> >>> >>> "Sid Price" <s**@nowhere.com> wrote in message >>> news:ORoNyOREIHA.5752@TK2MSFTNGP02.phx.gbl... >>>>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. >>>> >>>> >>>> >>>> >>> >>> >> >> > > 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. -- Show quoteHTH, Kevin Spencer Chicken Salad Surgeon Microsoft MVP "Sid Price" <s**@nowhere.com> wrote in message news:%23oGolVOFIHA.5360@TK2MSFTNGP03.phx.gbl... > 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. > > "Alvin Bruney [MVP]" <some guy without an email address> wrote in message > news:%23hRq6yeEIHA.4140@TK2MSFTNGP03.phx.gbl... >> 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. >> >> -- >> Regards, >> Alvin Bruney >> ------------------------------------------------------ >> Shameless Author Plug >> OWC Black Book 2nd Edition >> Exclusively on www.lulu.com/owc >> $24.99 >> >> >> "Sid Price" <s**@nowhere.com> wrote in message >> news:OaFOm4aEIHA.5980@TK2MSFTNGP04.phx.gbl... >>> 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. >>> >>> "sloan" <sl***@ipass.net> wrote in message >>> news:e4lKKCSEIHA.5360@TK2MSFTNGP03.phx.gbl... >>>> 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. >>>> >>>> >>>> >>>> >>>> "Sid Price" <s**@nowhere.com> wrote in message >>>> news:ORoNyOREIHA.5752@TK2MSFTNGP02.phx.gbl... >>>>>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. >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > 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. Show quote "Kevin Spencer" <unclechut***@nothinks.com> wrote in message news:%23RGYDOWFIHA.3716@TK2MSFTNGP03.phx.gbl... > 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. > > -- > HTH, > > Kevin Spencer > Chicken Salad Surgeon > Microsoft MVP > > "Sid Price" <s**@nowhere.com> wrote in message > news:%23oGolVOFIHA.5360@TK2MSFTNGP03.phx.gbl... >> 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. >> >> "Alvin Bruney [MVP]" <some guy without an email address> wrote in message >> news:%23hRq6yeEIHA.4140@TK2MSFTNGP03.phx.gbl... >>> 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. >>> >>> -- >>> Regards, >>> Alvin Bruney >>> ------------------------------------------------------ >>> Shameless Author Plug >>> OWC Black Book 2nd Edition >>> Exclusively on www.lulu.com/owc >>> $24.99 >>> >>> >>> "Sid Price" <s**@nowhere.com> wrote in message >>> news:OaFOm4aEIHA.5980@TK2MSFTNGP04.phx.gbl... >>>> 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. >>>> >>>> "sloan" <sl***@ipass.net> wrote in message >>>> news:e4lKKCSEIHA.5360@TK2MSFTNGP03.phx.gbl... >>>>> 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. >>>>> >>>>> >>>>> >>>>> >>>>> "Sid Price" <s**@nowhere.com> wrote in message >>>>> news:ORoNyOREIHA.5752@TK2MSFTNGP02.phx.gbl... >>>>>>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. >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > 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. -- Show quoteHTH, Kevin Spencer Chicken Salad Surgeon Microsoft MVP "Sid Price" <s**@nowhere.com> wrote in message news:%23rrOuAYFIHA.4748@TK2MSFTNGP06.phx.gbl... > 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. > > "Kevin Spencer" <unclechut***@nothinks.com> wrote in message > news:%23RGYDOWFIHA.3716@TK2MSFTNGP03.phx.gbl... >> 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. >> >> -- >> HTH, >> >> Kevin Spencer >> Chicken Salad Surgeon >> Microsoft MVP >> >> "Sid Price" <s**@nowhere.com> wrote in message >> news:%23oGolVOFIHA.5360@TK2MSFTNGP03.phx.gbl... >>> 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. >>> >>> "Alvin Bruney [MVP]" <some guy without an email address> wrote in >>> message news:%23hRq6yeEIHA.4140@TK2MSFTNGP03.phx.gbl... >>>> 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. >>>> >>>> -- >>>> Regards, >>>> Alvin Bruney >>>> ------------------------------------------------------ >>>> Shameless Author Plug >>>> OWC Black Book 2nd Edition >>>> Exclusively on www.lulu.com/owc >>>> $24.99 >>>> >>>> >>>> "Sid Price" <s**@nowhere.com> wrote in message >>>> news:OaFOm4aEIHA.5980@TK2MSFTNGP04.phx.gbl... >>>>> 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. >>>>> >>>>> "sloan" <sl***@ipass.net> wrote in message >>>>> news:e4lKKCSEIHA.5360@TK2MSFTNGP03.phx.gbl... >>>>>> 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. >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> "Sid Price" <s**@nowhere.com> wrote in message >>>>>> news:ORoNyOREIHA.5752@TK2MSFTNGP02.phx.gbl... >>>>>>>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. >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > 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. Show quote "Kevin Spencer" <unclechut***@nothinks.com> wrote in message news:uYVZ9IvFIHA.4752@TK2MSFTNGP04.phx.gbl... > 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. > > -- > HTH, > > Kevin Spencer > Chicken Salad Surgeon > Microsoft MVP > > "Sid Price" <s**@nowhere.com> wrote in message > news:%23rrOuAYFIHA.4748@TK2MSFTNGP06.phx.gbl... >> 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. >> >> "Kevin Spencer" <unclechut***@nothinks.com> wrote in message >> news:%23RGYDOWFIHA.3716@TK2MSFTNGP03.phx.gbl... >>> 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. >>> >>> -- >>> HTH, >>> >>> Kevin Spencer >>> Chicken Salad Surgeon >>> Microsoft MVP >>> >>> "Sid Price" <s**@nowhere.com> wrote in message >>> news:%23oGolVOFIHA.5360@TK2MSFTNGP03.phx.gbl... >>>> 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. >>>> >>>> "Alvin Bruney [MVP]" <some guy without an email address> wrote in >>>> message news:%23hRq6yeEIHA.4140@TK2MSFTNGP03.phx.gbl... >>>>> 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. >>>>> >>>>> -- >>>>> Regards, >>>>> Alvin Bruney >>>>> ------------------------------------------------------ >>>>> Shameless Author Plug >>>>> OWC Black Book 2nd Edition >>>>> Exclusively on www.lulu.com/owc >>>>> $24.99 >>>>> >>>>> >>>>> "Sid Price" <s**@nowhere.com> wrote in message >>>>> news:OaFOm4aEIHA.5980@TK2MSFTNGP04.phx.gbl... >>>>>> 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. >>>>>> >>>>>> "sloan" <sl***@ipass.net> wrote in message >>>>>> news:e4lKKCSEIHA.5360@TK2MSFTNGP03.phx.gbl... >>>>>>> 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. >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> "Sid Price" <s**@nowhere.com> wrote in message >>>>>>> news:ORoNyOREIHA.5752@TK2MSFTNGP02.phx.gbl... >>>>>>>>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. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > |
|||||||||||||||||||||||