Where do we output exception messages from App_Code\MyClass.cs?

G

gnewsgroup

In a web application, we do not have access to the Console.

And quite often, in order to share a class across the entire web
application, we put it under App_Code.

Normally, classes placed under App_Code do not inherit
System.Web.UI.Page, and therefore do not have access to Response.Write
or any of our Web controls.

Nor do we have a console.

So, here is my question: How do we handle exceptions thrown from, for
example, App_Code\MyClass.cs ?

Should we say something like below?

try
{
// blah blah
}
catch(SqlException se)
{
throw new Exception(se.Message);
}

Thank you!
 
G

Guest

Re-throwing Exceptions is more expensive (on the performance of the
application) than letting the exception to propagate automatically. So if
your class App_Code\MyClass.cs does not do anything with a caught exception,
remove the try ... catch block from it and let the web page to handle it.

You might find this article helpful:
http://msdn2.microsoft.com/en-us/library/ms954599.aspx#emag__exception_propagation
--
Regards,

Phillip Williams (MCPD Web Developer)
http://mcts-study-practices.com/
http://www.webswapp.com
 
G

gnewsgroup

Re-throwing Exceptions is more expensive (on the performance of the
application) than letting the exception to propagate automatically. So if
your class App_Code\MyClass.cs does not do anything with a caught exception,
remove the try ... catch block from it and let the web page to handle it.

You might find this article helpful: http://msdn2.microsoft.com/en-us/library/ms954599.aspx#emag__exceptio...

OK, thank you very much. I haven't been a good exception catcher.
But your idea helps clarify a major exception principle. Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top