JavaScript For Everyone: Iterators
1 day ago
Dim sw As New System.Diagnostics.Stopwatch
sw.Start()
'... Do some long code stuff here ...
sw.Stop()
Dim ts As TimeSpan = sw.Elapsed
lblErrorMessages.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", sw.Elapsed.Hours, sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds / 10)
Private Sub MyMethod()
Try
'...do something
Catch ex As Exception
Throw New Exception("MyMethod", ex)
End Try
End Sub
The code above is a big pet peave of mine because with code like the above you end up having to dig down through multiple InnerException objects to find the right exception message.Public Class Person
Implements IDisposable
Private m_FirstName As String = String.Empty
Private m_LastName As String = String.Empty
Public Property FirstName() As String
Get
Return m_FirstName
End Get
Set(ByVal value As String)
m_FirstName = value
End Set
End Property
Public Property LastName() As String
Get
Return m_LastName
End Get
Set(ByVal value As String)
m_LastName= value
End Set
End Property
Public Sub New()
End Sub
Public Function GetAddressByNameTheWrongWay(ByVal FirstName As String, ByVal LastName As String) As String
Try
'...do something and return
Catch ex as Exception
Throw New Exception("some dumb message here",ex)
End Try
End Sub
Public Function GetAddressByNameTheRightWay(ByVal FirstName As String, ByVal LastName As String) As String
'...do something and return
End Sub
End Class
Partial Class Maintenance_IVANSAgentApplications
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objPerson As New Person
'Lets call it the wrong way first.
Response.Write(objPerson.GetAddressByNameTheWrongWay(txtFirstName.text, txtLastName.text))
'Now lets call it the correct way.
Try
Response.Write(objPerson.GetAddressByNameTheWrongWay(txtFirstName.text, txtLastName.text))
Catch ex as Exception
Response.Write(ex.Message)
End Try
End Sub
End Class