Ramnarayan
Programmer
Hi,
I am trying to keep track of counting the # of times the program throws an exception. When the number crosses 3, It should throw an exception saying that number of tries are 3 and program is exiting.
Here is the main class (Centrigade to farenheit)
Imports System.Windows.Forms
Public Class CentrigatetoFahrenheit
Inherits Form
Public Function ctof(ByVal cnum As Double) As Double
Return (9 * (cnum / 5)) + 32
End Function
Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click
fLabel.Text = ""
Dim ctr As ExceptionCounter = New ExceptionCounter
Try
Dim ctofresult As Double = ctof(Convert.ToDouble(cTextBox.Text))
fLabel.Text = ctofresult.ToString
Catch format As FormatException
MessageBox.Show(format.Message, "Invalid Number Format", MessageBoxButtons.OK, MessageBoxIcon.Error)
!!!!! ctr = ctr + 1 'Not allowed by VB.NET
' Dim excctr As ExceptionCounter = New ExceptionCounter(1)
'Catch blank As BlankException
' MessageBox.Show(blank.Message, "Invalid Number Format", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class
Here is the exceptionCounter Class:
Public Class ExceptionCounter
Inherits ApplicationException
Private mctr As Integer
Public Sub New()
mctr = 0
End Sub
Public Sub New(ByVal ctr As Integer)
mctr = ctr
End Sub
Private Function excctr() As Integer
Return mctr = mctr + 1
End Function
End Class
I am trying to keep track of counting the # of times the program throws an exception. When the number crosses 3, It should throw an exception saying that number of tries are 3 and program is exiting.
Here is the main class (Centrigade to farenheit)
Imports System.Windows.Forms
Public Class CentrigatetoFahrenheit
Inherits Form
Public Function ctof(ByVal cnum As Double) As Double
Return (9 * (cnum / 5)) + 32
End Function
Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click
fLabel.Text = ""
Dim ctr As ExceptionCounter = New ExceptionCounter
Try
Dim ctofresult As Double = ctof(Convert.ToDouble(cTextBox.Text))
fLabel.Text = ctofresult.ToString
Catch format As FormatException
MessageBox.Show(format.Message, "Invalid Number Format", MessageBoxButtons.OK, MessageBoxIcon.Error)
!!!!! ctr = ctr + 1 'Not allowed by VB.NET
' Dim excctr As ExceptionCounter = New ExceptionCounter(1)
'Catch blank As BlankException
' MessageBox.Show(blank.Message, "Invalid Number Format", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class
Here is the exceptionCounter Class:
Public Class ExceptionCounter
Inherits ApplicationException
Private mctr As Integer
Public Sub New()
mctr = 0
End Sub
Public Sub New(ByVal ctr As Integer)
mctr = ctr
End Sub
Private Function excctr() As Integer
Return mctr = mctr + 1
End Function
End Class