2011-04-20 47 views
0

我还在寻找答案,而我还在努力这个Visual Studio的 开发使用VB.net语言的一些web应用程序...VB.net打印出try和catch

嗯....我其实是想印出我抓的消息, 但不知何故,如果我把这个...

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 

渔获不给我任何东西...... 如何打印输出在VB中醒目。净?

+0

尝试'ex.Message.ToString()'而不是 – 2011-04-20 09:10:21

+0

它是一个Web应用程序吗? – 2011-04-20 09:11:54

+0

@kalyan [Exception.Message](http://msdn.microsoft.com/en-us/library/system.exception.message.aspx)已经是一个字符串了。 ToString从对象继承。 – Smudge202 2011-04-20 09:23:41

回答

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