Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Error Handling with response.write

Reply
Thread Tools

Error Handling with response.write

 
 
Michael
Guest
Posts: n/a
 
      12-26-2003
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


 
Reply With Quote
 
 
 
 
Hermit Dave
Guest
Posts: n/a
 
      12-26-2003
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:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      12-26-2003
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" <(E-Mail Removed)> wrote in message
news:%23xl4$(E-Mail Removed)...
> 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:(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Kikoz
Guest
Posts: n/a
 
      12-26-2003
Another solution depends on how separate that class should
be from asp.net context. If it doesn't matter, then you
can simply pass Response to this class' constructor and
use it inside of it. Will work just fine.

Regards.


>-----Original Message-----
>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
>
>
>.
>

 
Reply With Quote
 
Shafqat Ahmed
Guest
Posts: n/a
 
      12-29-2003
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. <(E-Mail Removed)> 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" <(E-Mail Removed)> wrote in message
> news:%23xl4$(E-Mail Removed)...
>> 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:(E-Mail Removed)...
>> > 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/
 
Reply With Quote
 
Alvin Bruney
Guest
Posts: n/a
 
      12-29-2003
> 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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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. <(E-Mail Removed)>

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" <(E-Mail Removed)> wrote in

message
> > news:%23xl4$(E-Mail Removed)...
> >> 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:(E-Mail Removed)...
> >> > 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/



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
python list handling and Lisp list handling Mark Tarver Python 22 04-26-2009 09:36 PM
Is faster handling hexadecimal values than handling chars? IƱaki Baz Castillo Ruby 1 04-15-2008 09:04 AM
Global Error handling in Applicatio_Error() of Global.asax VSK ASP .Net 1 07-29-2003 03:12 AM
Error Handling Kenneth Keeley ASP .Net 0 07-01-2003 03:45 AM



Advertisments