VB.net打印出来试试并抓住

时间:2011-04-20 09:07:09

标签: vb.net try-catch

我还在寻找答案,而我还在尝试这个Visual Studio 使用VB.net语言开发一些Web应用程序...

嗯......我其实想要打印出我的捕获信息, 但不知何故,如果我把这个... ...

 Try
        Dim oCommand As MySqlCommand = New MySqlCommand("SELECT * FROM suppliermst WHERE supplierid = " & p_iSupplierId, oConnection)
        oConnection.Open()
        oReader = oCommand.ExecuteReader

        While oReader.Read
            oSuppliermst = New suppliermst
            oSuppliermst.supplierId = oReader("supplierid")
            oSuppliermst.name = oReader("name")
            oSuppliermst.state = oReader("state")
            oSuppliermst.telNo = oReader("telno")
            oSuppliermst.mobileNo = oReader("mobileno")
            oSuppliermst.faxNo = oReader("faxno")
            oSuppliermst.email = oReader("email")
            oSuppliermst.countryCode = oReader("countrycode")
            oSuppliermst.companyName = oReader("companyname")
            oSuppliermst.city = oReader("city")
            oSuppliermst.address1 = oReader("address1")
            oSuppliermst.address2 = oReader("address2")
            oSuppliermst.postCode = oReader("postcode")
        End While

    Catch ex As Exception
        'log here
        Console.WriteLine("error on getSuppliermstBySupplierId() function" & ex.Message)

    Finally
        closeMySqlDataReader(oReader)
        closeMySqlConnection(oConnection)
    End Try

Catch并没有给我任何东西...... 如何在VB.net中打印出文件?

2 个答案:

答案 0 :(得分:2)

除Subhash的响应外,如果控制台可用(即在Windows控制台应用程序中),您的应用程序将仅输出到控制台。

如果您想在调试时看到这些消息,请参阅以下帖子,其中介绍了如何将消息从Console.WriteLine发送到VS中的“输出”窗口(与使用Debug.Print的行为相同)。

redirect console to visual studio debug output window in app.config

如果要将消息输出到日志,可以使用与上面链接中说明的过程类似的过程。只需更改writeline功能即可打开文本文件write the message to the file

答案 1 :(得分:0)

这是一个网络应用程序吗?如果是,最好在日志文件中编写异常。这样,您可以在以后随时查看日志。