Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exception Catching Oddness

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
I have some code that goes

Code:
Dim DRDataTable As DataTable

Try
  FunctionThatReturnsADataset(MyDataSet)
  DRDataTable = MyDataSet.Tables(0)
  
  ' Processing ...
Catch ex As MyCustomException
 
End Try

Public Class MyCustomException
    Inherits System.Exception
    Public Sub New(ByVal Message As String)
        MyBase.New()
    End Sub
End Class
and when the dataset is empty and this line
DRDataTable = MyDataSet.Tables(0)
returns an error it does not get caught, why is this?
 
It's because you are only catching a MyCustomException. Since your objects don't know how to throw that custom exception, they won't. So you should catch a general exception.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top