Prev | Current Page 222 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

If there is a suitable Catch block in the same
frame as the Finally block, it will execute before the Finally block.
Throwing Exceptions
The act of throwing an exception is actually quite easy. You simply execute a Throw statement
where the parameter to the Throw statement is the exception you would like to throw. For
example, suppose you??™ve written a custom collection class that allows users to access items by
index, and you??™d like to notify users when an invalid index is passed as a parameter. You could
throw an ArgumentOutOfRange exception, such as in the following code:
Public Class MyCollection
Private Count As Integer
Public Function GetItem(ByVal index As Integer) As Object
If index < 0 OrElse index >= Count Then
Throw New ArgumentOutOfRangeException()
End If
End Function
End Class
The runtime can also throw exceptions as a side effect to code execution. An example of a
system-generated exception is NullReferenceException, which occurs if you attempt to access
a field or call a method on an object when, in fact, the reference to the object doesn??™t exist.
Unhandled Exceptions in .NET 3.5
When an exception is thrown, the runtime begins to search up the stack for a matching Catch
block for the exception. As it walks up the execution stack, it unwinds the stack at the same
time, cleaning up each frame along the way.


Pages:
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
wierszyki bajka Tango Olsztyn pozycjonowanie typy bukmacherskie