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.
Loading
bruno oliveiraPosted Mar 31, 2009, 3:09 PM
How did this ended?
Is there no better way on handling exceptions inside SoapExceptions!? :-(
[]s
Mahesh ChandPosted Feb 14, 2009, 9:25 AM
EdPosted Feb 14, 2009, 9:15 AM
Put simply: I'm trapping the soap exception as I should, but in this case, I only want to take action on the RowNotInTableException that is inside and display an error for the others. So, I'm wondering how to act only under those circumstances.
Ed.
Bechir BejaouiPosted Feb 13, 2009, 6:22 PM
Mahesh ChandPosted Feb 13, 2009, 8:25 AM
What happens when you get a non-soap error? Sometimes its advised to use generic error handling and nested specific error handling.
catch (Exception exp)
{
catch (SoapException error)
{
// thow this
}
// You do not have to throw this
}
OR you can also do this:
catch (Exception exp || SoapException error)
{
}
Bechir BejaouiPosted Feb 13, 2009, 5:09 AM
protected void Application_Error(Object sender, EventArgs e)
{
if (Server.GetLastError().InnerException != null)
{
Server.Transfer(/*the given url to the error customized page*/);
}
}
Or you can use Page_error instead
You can programm that by adding global.asax to your application. I advise you to digg into details with how to use the global.asax as an experienced programmer you will learn faster how to administer a web application through configuring global asax.
Or I propose another solution which is sure, becasue tested it. Open the configuration file of your application and add this within the
........
EdPosted Feb 12, 2009, 5:54 PM
Why do you ask?
Ed.
Bechir BejaouiPosted Feb 12, 2009, 5:35 PM