I am making my own utils project with static functions to use. I have this utility function:
which of course seems fine, but it doesn't report the error message to the given ToolStripStatusLabel component when I call it like so:Code:Public Sub OpenRecordSetForwardReadOnly(ByRef recordSet As ADODB.Recordset, ByVal sql As String, ByRef dbConn As ADODB.Connection, Optional ByVal statusBar As ToolStripStatusLabel = Nothing) Try recordSet.Open(sql, dbConn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, ADODB.CommandTypeEnum.adCmdText) Catch ex As Exception Dim funcName As String = System.Reflection.MethodInfo.GetCurrentMethod().Name Dim msg As String = funcName & ": " & ex.Message & ", Source: " & ex.Source & ", StackTrace: " & ex.StackTrace Console.WriteLine(msg) If Not IsNothing(statusBar) Then statusBar.Text = msg End If End Try End Sub
Instead it breaks the application with exception that the operation is not allowed when the object is closed(accessing table that doesn't exist with the given name.)Code:Private Sub checkExistingDataBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles izlezBtn.Click Dim rs as new ADODB.RecordSet myUtils.OpenRecordSetForwardReadOnly(rs, someSelectSQLString, db2Conn, Me.statusbarTB) End Sub
Well I can add Try/Catch block
but that is not the point of the utils function since it has its own Try/Catch block.Code:Private Sub checkExistingDataBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles izlezBtn.Click try Dim rs as new ADODB.RecordSet myUtils.OpenRecordSetForwardReadOnly(rs, someSelectSQLString, db2Conn, Me.statusbarTB) Catch ex As Exception Dim funcName As String = System.Reflection.MethodInfo.GetCurrentMethod().Name Dim msg As String = funcName & ": " & ex.Message & ", Source: " & ex.Source & ", StackTrace: " & ex.StackTrace Console.WriteLine(msg) statusBar.Text = msg end Try End Sub
How can I report exception message to status bar without adding additional Try/Catch block?




Reply With Quote
