end routine

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a C# webmethod that returns a dataset, What i want to do is if an
error occurs to call the error method and pass that back to the front end
client app.
i have
public dataset names()
{
dbconnection;
try
{
//excute SP's
}
catch (Exception e)
{
logErrors(e.message) // if this then call logErrors then stop
processing this method
}
return dataset
}
 
Mike,

You can re-throw the error, like so:

public dataset names()
{
dbconnection;
try
{
//excute SP's
}
catch (Exception e)
{
logErrors(e.message) // if this then call logErrors then stop
processing this method

// Re-throw the exception.
throw;
}
return dataset
}

This will re-throw the error. Now it is interesting that you bring up
that this is a web method. You *might* be able to eliminate the error
handling from your code altogether (at least in the web method itself).
What you might be able to do is create an implementation of IHttpHandler and
then pass through to the default handler. Basically, upon return, you would
check the response to see if there is an exception in it. If there is, then
you would log it, and then let the result return normally. This would
eliminate the need to place try/catch blocks everywhere and re-throw the
exception.

Hope this helps.
 
Back
Top