Ed

Ed

  • NA
  • 8
  • 0

Advice on Exception Handling.

Feb 12 2009 4:41 PM
Hi All,

I just recently took some extensive training on my own learning C# and WebServices. I'm an experienced programmer but relatively new to OO and C#. As a result of that training, I built a Library Management System. This system uses a web service and both an ASP.NET application and a Windows Client.

I'm still trying to get some things figured out, so am posting for advice on the best way to handle certain issues with regards to this LMS, starting with exception handling. In one scenario, I have an Add Book function that reads for the existance of a book, and if it doesn't exist, creates a new ID for it. The problem is, the exception the client is handling is a SoapException, with a RowNotInTableException embedded in it. In order to trap the error, I am handling it like this:
==========
catch (SoapException error) {
  if (error.Message.Contains("Book could not be found.")) {
    AddMode();
    OpenTitle();
  }
  else
    throw error;
}
==========

I know this is not the best way to handle this, but I've also tried handling it like this:
==========
  catch (SoapException error) {
  if (error.InnerException is RowNotInTableException) {
    AddMode();
    OpenTitle();
  }
  else
    throw error;
}
==========

This fails and tells me the exception is unhandled. So, it is hitting the throw error statement in my catch block.

So, what advice does anyone have on the best way to handle this issue? Any and all clues welcome.

Ed.

Answers (8)