Try Catch When

Quite frankly, I didn’t knew that there’s even a WHEN clause to the TRY-CATCH block. Thanks to Eric Porter for sharing this tip!

Public Shared Function SaveChangesToServer(ByVal ShouldThrowException As Boolean) As Boolean
          Try
               ' Do some stuff
          Catch Ex As Exception When ShouldThrowException
               'Clean-up
               Throw Ex
          Catch
               'Clean-up
          End Try
     Return Success
End Function
Show Comments