> WriteException (Exception e)
> {
> if (HttpContext.Current!=nothing)
> {
> HttpContext.Current.Response.Write (ex.Message)
> }
> else
> {
> // Skip since we are not running from ASP.NET
> }
This code, though well intentioned, will not work as intended because the
context object is always null outside of the page - as in a user class for
example. What is needed is a way to pass a reference of the context object
to the class library.
I posted this to another newsgroup. It applies here as well.
You can pass in the context object which houses the request and response
object for an application to your method. Your method will contain the logic
to manipulate the response and request objects. Consider:
private void somefunction(System.Web.HttpContext Stream)
{
Stream.Session["session_id"] = "value";
}
> >> > Unfortunately Response.anything from within my class generate a
> > "Response
> >> is
> >> > not declared" error. How can I get Response to work from within a
> > class,
Armed with this general idea, you can adapt your class to take a reference
to the context object when it is instantiated. When you need to touch the
response object, you will touch it thru the reference provided in your
class. As always, be careful to properly release resources when they aren't
needed.
--
Regards,
Alvin Bruney
Got DotNet? Get it here
http://home.networkip.net/dotnet/tidbits/default.htm
"Shafqat Ahmed" <> wrote in message
news

...
> Try something like this. Theoratically this should work
>
> Your code
>
> try
> {
> Code .....
> }
> catch (Exception e)
> {
> WriteException ( e);
> }
>
> Another function ...
>
> WriteException (Exception e)
> {
> if (HttpContext.Current!=nothing)
> {
> HttpContext.Current.Response.Write (ex.Message)
> }
> else
> {
> // Skip since we are not running from ASP.NET
> }
>
> }
>
> Thanks
> Shiplu
>
> On Fri, 26 Dec 2003 11:42:40 -0500, Scott M. <s->
wrote:
>
> > Don't have the class attempt to provide any kind of user interface.
> > Instead, use a Try...Catch and in the Catch, throw a new exception that
> > will
> > bubble up to the applicaiton that is calling the class. This
applicaiton
> > hand then display details about the exception in its interface.
> >
> >
> > "Hermit Dave" <> wrote in
message
> > news:%23xl4$...
> >> michael,
> >>
> >> well try not handling the exception at that point instead use a global
> > error
> >> handler something like application_error
> >> which can check the type of exception and do a server.transfer
> >> (response.redirect would clear the error) to appropraite page to show
> >> the
> >> error
> >> or if you like to display it with calling page.... try wrapping a try
> > catch
> >> block when you the the database object.
> >> catch the exception from within your aspx page
> >>
> >> hope this helps
> >>
> >> hd
> >>
> >> "Michael" <raterus@localhost> wrote in message
> >> news:...
> >> > Hello,
> >> > I have a separate Database class that handles any database work that
> >> all
> >> my
> >> > asp.net pages can use.
> >> >
> >> > My problem is, many times I use try/catch to catch errors, and I want
> >> to
> >> > output these errors to the webpage with response.write().
> >> >
> >> > Unfortunately Response.anything from within my class generate a
> > "Response
> >> is
> >> > not declared" error. How can I get Response to work from within a
> > class,
> >> or
> >> > is there a better way to handle errors in asp.net classes.
> >> >
> >> > Thanks,
> >> > --Michael
> >> >
> >> >
> >>
> >>
> >
> >
>
>
>
> --
> Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/