M
Malcolm
I'm having problems displaying the full error information for an error
if the error is passed through a function that uses the finally
statement as part of the error handling. The function where it loses
the innerexception error objects is as follows:
Private Sub DoSomething()
Try
conn = New OleDbConnection(GetDatabaseConnectionString)
conn.Open()
...
... some database code which fails
...
Catch ex as Exception
Throw ex
Finally
conn.close
End Try
End Sub
In this example, i want to use the finally statement to make sure the
database connection is closed.
When an error is received in the code above, the catch statement is
processed and at that point, all the error objects are visible through
the innerexception. However, when the error is raised to the function
calling this (and the catch statement), the ex object is not set and i
get the error message: "Object reference not set to an instance of an
object.".
When i remove the Finally section, the parent code correctly has the
details of all internal errors.
Does anyone know how to resolve this?
I have tried declaring a new exception object at the top of the
function to make sure it would stil be in scope in the finally clause,
but this didnt work either.
Thanks
Malcolm
if the error is passed through a function that uses the finally
statement as part of the error handling. The function where it loses
the innerexception error objects is as follows:
Private Sub DoSomething()
Try
conn = New OleDbConnection(GetDatabaseConnectionString)
conn.Open()
...
... some database code which fails
...
Catch ex as Exception
Throw ex
Finally
conn.close
End Try
End Sub
In this example, i want to use the finally statement to make sure the
database connection is closed.
When an error is received in the code above, the catch statement is
processed and at that point, all the error objects are visible through
the innerexception. However, when the error is raised to the function
calling this (and the catch statement), the ex object is not set and i
get the error message: "Object reference not set to an instance of an
object.".
When i remove the Finally section, the parent code correctly has the
details of all internal errors.
Does anyone know how to resolve this?
I have tried declaring a new exception object at the top of the
function to make sure it would stil be in scope in the finally clause,
but this didnt work either.
Thanks
Malcolm