1. Find & show the inheritance hierarchy for the above exception types. (Read the documentation at MSDN)
OverflowException:
System.Object
System.Exception
System.SystemException
System.ArithmeticException
System.OverflowException
InvalidCastException:
System.Object
System.Exception
System.SystemException
System.InvalidCastException
IndexOutOfRangeException:
System.Object
System.Exception
System.SystemException
System.IndexOutOfRangeException
NullReferenceException:
System.Object
System.Exception
System.SystemException
System.NullReferenceException
Tuesday, August 17, 2010
Keyword for throwing an exception
1. Which keyword is used to throw an exception?
"Throw"
2. Looking at the diagram below, discuss the options for exception handling. Should the exception be handled? If so, where should it be handled? Should it be rethrown? Why? Why not?

The exception should be handled on A and should be rethrown at B and C. This is because A is calling B and B is calling C. If C gets an exception, that should be rethrown for B and then B should rethrow it to A so it can be handled properly.
"Throw"
2. Looking at the diagram below, discuss the options for exception handling. Should the exception be handled? If so, where should it be handled? Should it be rethrown? Why? Why not?

The exception should be handled on A and should be rethrown at B and C. This is because A is calling B and B is calling C. If C gets an exception, that should be rethrown for B and then B should rethrow it to A so it can be handled properly.
Inheriting the exception class
1. What Visual Basic keyword is used to implement inheritance in a class?
"Inherits"
2. In the event of an exception, what does the Message property of the Exception class contain?
It contains a string that tells the user what the problem is.
Which keyword gives a child class access to all of it’s parent’s public & protected members?
"MyBase"
What is the first statement in a child class constructor?
"MyBase.New(ErrorMessage)"
"Inherits"
2. In the event of an exception, what does the Message property of the Exception class contain?
It contains a string that tells the user what the problem is.
Which keyword gives a child class access to all of it’s parent’s public & protected members?
"MyBase"
What is the first statement in a child class constructor?
"MyBase.New(ErrorMessage)"
Monday, August 9, 2010
NullReferenceException Questions
1. What warning does the Visual Studio IDE provide with regards to using variables before they have been assigned a value? What does the warning look like? What does it say?
Variable 'ThisPlayer1' is used before it has been assigned a value. A null reference exception could result at runtime.
2. Post a screen shot of the resulting message box.
Variable 'ThisPlayer1' is used before it has been assigned a value. A null reference exception could result at runtime.
2. Post a screen shot of the resulting message box.
OverflowException Questions
1. What is the name of the Visual Basic function (not discussed in this doc, you may like to go back to Automate Processes if you don’t know) we could use to ensure that only numeric data is assigned to the integer variable (therefore avoiding the program crash if non-numeric data is entered)?
IsNumeric()
2. Why does the OverFlowException occur?
It occurs when the value exceeds the limits of the integer data type.
If Below −2,147,483,648
If Above 2,147,483,647
3. What is the range/capacity of an integer?
−2,147,483,648 to 2,147,483,647
4. How would we implement this method? Modify the code to implement the function.
You check to make sure the Integer is not above 2,147,483,647 and is not below −2,147,483,648.
5. Post a screenshot of your code.
IsNumeric()
2. Why does the OverFlowException occur?
It occurs when the value exceeds the limits of the integer data type.
If Below −2,147,483,648
If Above 2,147,483,647
3. What is the range/capacity of an integer?
−2,147,483,648 to 2,147,483,647
4. How would we implement this method? Modify the code to implement the function.
You check to make sure the Integer is not above 2,147,483,647 and is not below −2,147,483,648.
5. Post a screenshot of your code.
InvalidCastException Questions
1. Why does the InvalidCastException occur?
It's trying to set an integer to a value which is a string.
2. What happens if you enter a number within the integer range?
It casts the value correctly and doesn't crash.
3. What is the correct data type to store a string in?
A String
4. What is the correct data type to store a number in?
An Integer
5. Can you store a number in a string variable?
Yes.
It's trying to set an integer to a value which is a string.
2. What happens if you enter a number within the integer range?
It casts the value correctly and doesn't crash.
3. What is the correct data type to store a string in?
A String
4. What is the correct data type to store a number in?
An Integer
5. Can you store a number in a string variable?
Yes.
IndexOutOfRangeException Questions
1. What is the upperbound of the array?
2
2. How many elements are contained within the array?
3
3. How should this loop be primed? - that is - what do you suggest as a starting value and an ending value?
Starting Value = 0
Ending Value = 2
4. Why does the code in figure 4 produce an IndexOutOfRangeException?
It produces an Exception error because the Ending Value is equal to 3, this is outside the UpperBounds of the array.
5. What value is displayed in the message box when the loop is in it’s second iteration?
"String 2"
6. Post a screen shot of the message box produced in it’s second iteration.
2
2. How many elements are contained within the array?
3
3. How should this loop be primed? - that is - what do you suggest as a starting value and an ending value?
Starting Value = 0
Ending Value = 2
4. Why does the code in figure 4 produce an IndexOutOfRangeException?
It produces an Exception error because the Ending Value is equal to 3, this is outside the UpperBounds of the array.
5. What value is displayed in the message box when the loop is in it’s second iteration?
"String 2"
6. Post a screen shot of the message box produced in it’s second iteration.
Monday, August 2, 2010
Loop Blog Post 2
1. What is the UpperBound of the array?
2, The UpperBound of the array is the maximum index number (Size of the Array minus one)
2. How many elements are contained in the array?
2, The UpperBound of the array is the maximum index number (Size of the Array minus one)
3. What is the starting index of the array?
0
4. What is the starting value of the loop counter?
0
5. How many times does the loop execute?
3
6. What is the concatenation operator?
"&"
Screenshot:
2, The UpperBound of the array is the maximum index number (Size of the Array minus one)
2. How many elements are contained in the array?
2, The UpperBound of the array is the maximum index number (Size of the Array minus one)
3. What is the starting index of the array?
0
4. What is the starting value of the loop counter?
0
5. How many times does the loop execute?
3
6. What is the concatenation operator?
"&"
Screenshot:
Loop Blog Post 1
1. What is a Loop Counter?
A loop counter is a looping mechanism available in VB.NET that basically sets a variable to a value and then proceeds to increment a that variable every loop until it reaches the ending condition.
2. How many times does the Loop Execute?
The loop executes 100 times (99 if you only count every time it hits 'Next')
3. What is the final value of the NumberAccumulator variable?
100
Screenshot:
A loop counter is a looping mechanism available in VB.NET that basically sets a variable to a value and then proceeds to increment a that variable every loop until it reaches the ending condition.
2. How many times does the Loop Execute?
The loop executes 100 times (99 if you only count every time it hits 'Next')
3. What is the final value of the NumberAccumulator variable?
100
Screenshot:
Subscribe to:
Posts (Atom)