I have a method as follows:
Public Sub Send()
Dim caughtException As Exception = Nothing
Try
//Attempt action.
Catch ex As Exception //Custom exceptions which can be thrown all inherit from Exception.
//Instantiate error object to be logged.
caughtException = ex
End Try
//Log action and if there is an error log this too.
If caughtException IsNot Nothing Then Throw caughtException
End Sub
It is essential that I log the error for reports, which after research, rethrowing the exception is the right thing to do. What I am concerned about is preservation of stack information.
In order to keep the code DRY I am logging the action in one place – after the exception has been caught.
This functionality is ultimately exposed via WCF.
It better to log in the handler and then throw from there. Other wise you lose the stack and other details from the original exception.
Also when exposing functionality over WCF should ensure that the exception code is available on the client side if you have custom exceptions as need to transport them using WCF faults.
This is really important if the consumer is not .net you need to expose FaultContracts that contain details of the problem that will be decoded by the client. See here for details : WCF Web Service Custom Exception Error to Client