Writing an exception to both the event log and to an error page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TmFt?=

    Writing an exception to both the event log and to an error page

    In a C# class of an ASP.NET application, I am logging the exceptions to the
    windows even log. How can I simultaneously propagate the exception on top and
    let the Page that calls that C# class to catch the exception?

    After catching the exception, I would redirect a customized message to an
    error page.

    Thank you in advance.
  • =?Utf-8?B?Sko=?=

    #2
    RE: Writing an exception to both the event log and to an error page

    Should just have to rethrow it.

    Try
    <code>
    Catch Ex as Exception
    <code here to log to event log>
    Throw Ex
    End Try

    "Nam" wrote:
    In a C# class of an ASP.NET application, I am logging the exceptions to the
    windows even log. How can I simultaneously propagate the exception on top and
    let the Page that calls that C# class to catch the exception?
    >
    After catching the exception, I would redirect a customized message to an
    error page.
    >
    Thank you in advance.

    Comment

    • sloan

      #3
      Re: Writing an exception to both the event log and to an error page


      I would try this, which I think keeps the original stack trace.


      try
      {

      }
      catch (Exception ex)
      {

      //publish it to the event log
      throw;

      }


      Or change it to
      throw ex;

      But there is a subtle difference.



      "JJ" <JJ@discussions .microsoft.comw rote in message
      news:FC51B29C-FF7C-4289-8674-02206BA074ED@mi crosoft.com...
      Should just have to rethrow it.
      >
      Try
      <code>
      Catch Ex as Exception
      <code here to log to event log>
      Throw Ex
      End Try
      >
      "Nam" wrote:
      >
      >In a C# class of an ASP.NET application, I am logging the exceptions to
      >the
      >windows even log. How can I simultaneously propagate the exception on top
      >and
      >let the Page that calls that C# class to catch the exception?
      >>
      >After catching the exception, I would redirect a customized message to an
      >error page.
      >>
      >Thank you in advance.

      Comment

      • =?Utf-8?B?TmFt?=

        #4
        RE: Writing an exception to both the event log and to an error pag

        JJ,

        Thank you very much. I used your suggestion and it worked perfectly.

        Nam

        "JJ" wrote:
        Should just have to rethrow it.
        >
        Try
        <code>
        Catch Ex as Exception
        <code here to log to event log>
        Throw Ex
        End Try
        >
        "Nam" wrote:
        >
        In a C# class of an ASP.NET application, I am logging the exceptions to the
        windows even log. How can I simultaneously propagate the exception on top and
        let the Page that calls that C# class to catch the exception?

        After catching the exception, I would redirect a customized message to an
        error page.

        Thank you in advance.

        Comment

        Working...