Microsoft code creates error

P

Patrick Nolan

I am using the following code from Microsoft's support site :
public void Page_Error(object sender,EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string err = "<b>Error Caught in Page_Error event</b><hr><br>" +
"<br><b>Error in: </b>" + Request.Url.ToString() +
"<br><b>Error Message: </b>" + objErr.Message.ToString()+
"<br><b>Stack Trace:</b><br>" + objErr.StackTrace.ToString();
Response.Write(err.ToString());
Server.ClearError();
}

but when I run my program
I get :
Object reference not set to an instance of an object.
with the "Exception objErr = Server.GetLastError().GetBaseException();" line
highlighted.
I also tried putting this line above the objErr initialization:

Exception objErr = new Exception();

But I get the same error.
Any ideas would be apprectiated.
Thanks,
Patrick
(e-mail address removed)
 
J

John Saunders

Take it a step at a time. Try:

string err;
Exception lastError = Server.GetLastError();
if (lastError == null)
{
err = "Server.GetLastError() is null";
}
else
{
Exception objErr = lastError.GetBaseException();
if (objErr == null)
{
err = "lastError.GetBaseException() is null";
}
else
{
err = "<b> ...";
}
}
--
John Saunders
John.Saunders at SurfControl.com


Patrick Nolan said:
I am using the following code from Microsoft's support site :
public void Page_Error(object sender,EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string err = "<b>Error Caught in Page_Error event</b><hr><br>" +
"<br><b>Error in: </b>" + Request.Url.ToString() +
"<br><b>Error Message: </b>" + objErr.Message.ToString()+
"<br><b>Stack Trace:</b><br>" + objErr.StackTrace.ToString();
Response.Write(err.ToString());
Server.ClearError();
}

but when I run my program
I get :
Object reference not set to an instance of an object.
with the "Exception objErr = Server.GetLastError().GetBaseException();" line
highlighted.
I also tried putting this line above the objErr initialization:

Exception objErr = new Exception();

But I get the same error.
Any ideas would be apprectiated.
Thanks,
Patrick
(e-mail address removed)




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 

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