In a webservice I see this code:
<WebMethod()> _
Public Function dosomething() As Boolean
Try
If successful Then
Return True
Else
Return False
End If
Catch ex As Exception
Throw ex
End Try
End Function
What's the point of catching the exception and just throwing it again? Do I miss something?
Edit: Thanks for the answers! I thought it was something like that, but wasn't sure if I could/would refactor those away without any implications.
Don't do this.
If you absolutely need to rethrow the exception, just use throw;
using throw ex;
erases the stack trace and is absolutely wrong.
I can think of no reason to do this for functionality. However, it can arise when previously there was some error handling (logging usually) that has been removed, and the developer removed the log handling but did not restructure the code to remove the redundant try/catch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With