2
Answers

how to write the exception with out change of the code in as

narasiman rao

narasiman rao

7y
236
1
i have four pages as follows


home.aspx

trips.aspx

kyc.aspx

adhoc.aspx

for the above four page i did not write exception. with out change of the code how to write the exception for all the four pages in asp.net


for that how can i do in asp.net
Answers (2)
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 7y
You can use web.config to add custom error page. But one problem is you cannot log the exception.
  1. <configuration>  
  2.   <appSettings/>  
  3.   <connectionStrings/>  
  4.   <system.web>  
  5.     <compilation debug="true" />  
  6.   
  7.     <!-- Turn on Custom Errors -->  
  8.     <customErrors mode="On"   
  9.       defaultRedirect="DefaultRedirectErrorPage.aspx">  
  10.       <error statusCode="404" redirect="Http404ErrorPage.aspx"/>  
  11.     </customErrors>  
  12.   
  13.   </system.web>  
  14. </configuration>  
So it is better to use Global.asax to get exception and logit.
  1. void Application_Error(object sender, EventArgs e)  
  2. {  
  3.   // Code that runs when an unhandled error occurs  
  4.   
  5.   // Get the exception object.  
  6.   Exception exc = Server.GetLastError();  
  7.   
  8.   // For other kinds of errors give the user some information  
  9.   // but stay on the default page  
  10.   Response.Write("<h2>Global Page Error</h2>\n");  
  11.   Response.Write(  
  12.       "<p>" + exc.Message + "</p>\n");  
  13.   Response.Write("Return to the <a href='Default.aspx'>" +  
  14.       "Default Page</a>\n");  
  15.   
  16.   // Log the exception and notify system operators  
  17.   ExceptionUtility.LogException(exc, "DefaultPage");  
  18.   
  19.   // Clear the error from the server  
  20.   Server.ClearError();  
  21. }  
0
Ramesh Palanivel

Ramesh Palanivel

NA 9.5k 138.4k 7y
Hi Narasiman,
 
I think you cannot do this without touching the code, Surely you need to touch the code to implement custom error handling or common try catch exception.
 
You may find some other way to do this. If I know , I will reply soon.