Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Structured error handling practises in asp.net

Structured error handling practises in asp.net

Scheduled Pinned Locked Moved Design and Architecture
helpcsharpasp-netdatabasequestion
3 Posts 2 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shaunll
    wrote on last edited by
    #1

    Hi, I have a query regarding what would be a 'best practice' for SEH in an asp.net web app. At present I have Object as my return type from class functions. Within these functions use a try...catch block and return an error object if there's an error or the correct type, say datatable if the process completes as expected. The calling sub then evaluates the returned type and acts accordingly. While this works ok for me, it is a bit long winded and I can't help feeling I am missing the point somewhere. What do you guys do? Thanks if anyone has any tips. Shaun If I had all the money I'd spent on drink, I'd spend it on drink - Sir Henry at Rawlinson's End

    E 1 Reply Last reply
    0
    • S shaunll

      Hi, I have a query regarding what would be a 'best practice' for SEH in an asp.net web app. At present I have Object as my return type from class functions. Within these functions use a try...catch block and return an error object if there's an error or the correct type, say datatable if the process completes as expected. The calling sub then evaluates the returned type and acts accordingly. While this works ok for me, it is a bit long winded and I can't help feeling I am missing the point somewhere. What do you guys do? Thanks if anyone has any tips. Shaun If I had all the money I'd spent on drink, I'd spend it on drink - Sir Henry at Rawlinson's End

      E Offline
      E Offline
      Eugene Ciloci
      wrote on last edited by
      #2

      Exceptions are special in that when one is thrown, the .NET runtime will go up the function call-stack until it finds a catch block that can handle the exception. What this means is that you can put a try-catch at the "root" function (the one that calls all the other functions) and any exceptions thrown by any lower functions will be caught in the root function's catch block. Here's an example:

      Sub Main()
      Try
      DoStuff1()
      Catch ex As Exception
      ' Handle exception
      End Try
      End Sub

      Private Sub DoStuff1()
      DoStuff2()
      End Sub

      Private Sub DoStuff2()
      DoStuff3()
      End Sub

      Private Sub DoStuff3()
      ' Generate an exception
      End Sub

      If DoStuff3 generates an exception, .NET will jump to the catch block in Main. This way you can assume that all the values returned from your functions will be correct since if there was an error in the function, .NET would jump to the outer catch block, skipping any code that used the return value.

      S 1 Reply Last reply
      0
      • E Eugene Ciloci

        Exceptions are special in that when one is thrown, the .NET runtime will go up the function call-stack until it finds a catch block that can handle the exception. What this means is that you can put a try-catch at the "root" function (the one that calls all the other functions) and any exceptions thrown by any lower functions will be caught in the root function's catch block. Here's an example:

        Sub Main()
        Try
        DoStuff1()
        Catch ex As Exception
        ' Handle exception
        End Try
        End Sub

        Private Sub DoStuff1()
        DoStuff2()
        End Sub

        Private Sub DoStuff2()
        DoStuff3()
        End Sub

        Private Sub DoStuff3()
        ' Generate an exception
        End Sub

        If DoStuff3 generates an exception, .NET will jump to the catch block in Main. This way you can assume that all the values returned from your functions will be correct since if there was an error in the function, .NET would jump to the outer catch block, skipping any code that used the return value.

        S Offline
        S Offline
        shaunll
        wrote on last edited by
        #3

        I see... Thanks

        Shaun If I had all the money I'd spent on drink, I'd spend it on drink.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups