Problem with Try


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problem with Try

  1. #1
    Join Date
    Aug 2006
    Posts
    3

    Problem with Try

    Hi,

    I have a function that captures an exception and calls a subroutine to save the exception message. Within the called subroutine I have a try catch coded. When I run the program the called subroutine catches the previous exception within its catch portion.

    Can you help me and let me know where I'm going wrong.

    Here is the code in question:

    Function :

    Try

    sHeaderRef = "null"

    For Each DataRow In DSXML.Tables(0).Rows
    sSQL = "insert into tblDWPHeader " & _
    "(CreditorID,BatchNumber," & _
    "PacsDocumentCreationDate," & _
    "PacsDocumentCreationTime," & _
    "NotificationReference) " & _
    "values('" & _
    DataRow("CreditorID") & "','" & _
    DataRow("BatchNumber") & "','" & _
    DataRow("PacsDocumentCreationDate") & "','" & _
    DataRow("PacsDocumentCreationTime") & "','" & _
    DataRow("NotificationReference") & "')"

    Command.CommandText = sSQL
    Command.ExecuteNonQuery()

    Catch e As Exception

    Trans.Rollback()
    ImportMsg(xFullFileName & " - " & e.Message, 2, xConnection)

    Finally


    Private Sub ImportMsg(ByVal xMsg As String, ByVal ErrorLevel As Integer, ByVal xConnection As String)

    Dim SQLConn As New SqlConnection(xConnection)
    Dim Command As New SqlCommand()

    Try

    Console.WriteLine("DWP Import Error : " & xMsg)

    SQLConn.Open()
    Command.Connection = SQLConn

    Command.CommandText = "exec sp_AddImportMsg '" & _
    xMsg.Replace("'", "''") & "', " & ErrorLevel
    Command.ExecuteNonQuery()

    Catch ex As Exception
    MsgBox(ex.Message)
    Console.WriteLine("ImportMsg failed : " & ex.Message)
    Environment.Exit(2)

    Finally
    SQLConn.Close()

    Command.Dispose()
    SQLConn.Dispose()
    End Try

    End Sub

    Many Thanks,

    Andy Rowland.

  2. #2
    Join Date
    Mar 2005
    Posts
    71
    Eny Try of the 1st Try block is missing

  3. #3
    Join Date
    Aug 2006
    Posts
    3

    Still having problem with TRY

    Thanks for response. The End Try is present in my code, just did not include within my post.

    Still have problem.

    The first catch has generated an error. When control is passed to ImportMsg sub routine. The try does not generate a new error, however the catch throws the first error generated by the first catch. How can I code around this??????

    Regards,

    Andy.

Similar Threads

  1. Problem with Search
    By Irina in forum ASP.NET
    Replies: 0
    Last Post: 11-29-2002, 11:47 PM
  2. Replies: 0
    Last Post: 12-13-2001, 01:06 PM
  3. a problem with font and language
    By Roseta in forum VB Classic
    Replies: 0
    Last Post: 11-14-2001, 04:24 AM
  4. Arabic problem view
    By Ayman in forum VB Classic
    Replies: 0
    Last Post: 04-03-2000, 02:08 AM
  5. Problem with CryptoAPI and JCE
    By Jason Bock in forum VB Classic
    Replies: 0
    Last Post: 03-21-2000, 07:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center