Brilliant exception handling I found in an app i had to work on

  • @CatPoop
    link
    1
    edit-2
    1 year ago

    An exception will bubble up the stack until it enters a catch block that can handle it, and you may need additional logic to decide if you are finished, or it needs to go further up. (you may also intercept it just to add more data, or log it)

    throw; allows you send the original exception further up, but throw ex; behaves the same as throwing a new Exception object, and therefore has a new trace. The throw statement doesn’t query any properties on the exception argument AFAIK, so it has no idea this exception has been previously thrown, but the IDE is smart enough to know you almost certainly don’t want to do this.