Monday, August 3, 2009

Chapter 7 - Exception Handling

Exception handling = handling errors
Expect the worst from users

Allows the program to elegantly negotiate the error

To work with numeric:
try
intNumber=txtTextBox.Text
Catch ThisException As Exception
'reporting
'reporting
End try

Exception is a Class Object

AgumentNullException is a variable that has no value is passed to a procedure
Dim strTerm As String
Me.lstDisplay.Items.Add(strTerm)

DivideByZeroException is where a value is divided by zero
intResult= intNum / 0

FormatException - A format is converted to another type that is not possible
strTerm = "Code"
intValue = Convert.ToInt32(strTerm)

NullReferenceException - A procedure is called when the result is not possible
Dim strTerm As String
intValue = strTerm.Length

OverflowException = A value exceeds its assigned data type
Dim intCost as Integer
intCost = 58 ^ 4000000000

System Exception - Generic
Catches all other exceptions

No comments:

Post a Comment