BackgroundWorker vs Try/Catch?
Hi. I have an app that spawns a couple of BackgroundWorkers. The process works perfectly when all the target servers are available.
For testing purposes, I added some non-existant servers to the mix.
The problem is in the Try/Catch block of the background process. I have to connect to a SQL Server first, then do stuff. Even though I handle the problem to gracefully exit, I keep getting the message in Debug mode.
TargetInvocationException was unhandled
- Exception has been thrown by the target of an invocation.
-InnerException.Message: {"Object reference not set to an instance of an object."}
I thought maybe this was a noob question similar to VB6's option "Break on all errors/Break on unhandled errors," but I don't have ths problem on first-level Try/Catch blocks.
Simplified Code:
Function Catalog_Datasource( _
ByVal Datasource As String, _
ByVal worker As BackgroundWorker, _
ByVal e As DoWorkEventArgs) As String
Dim result as String = ""
Try
'Connect to SQL Server
Catch ex As Exception
GoTo Err_Handler
End Try
'do stuff<- I hit the error doing stuff
result = "Completed"
Return result
Exit Function
Err_Handler:
result = "Error"
End Function

