Why is this an issue?
Throwing an exception from within a finally block will mask any exception which was previously thrown in the try
or catch
block, and the masked’s exception message and stack trace will be lost.
Noncompliant code example
Try
' Some work which end up throwing an exception
Throw New ArgumentException()
Finally
' Clean up
Throw New InvalidOperationException() ' Noncompliant; will mask the ArgumentException
End Try
Compliant solution
Try
' Some work which end up throwing an exception
Throw New ArgumentException()
Finally
' Clean up
End Try