-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: shri
Message 5 in Discussion
Hi, You are getting confused with the basic concept of throwing errors. You can
define your own exception and catch them. Don't just hang ON with the keyword "Throw"
and "Throw ex". They are nothing but:
Throwing an Exception <O:P> </O:P>
In VB.NET, it is possible to throw an exception programmatically. The �throw� keyword
is used for this purpose. SYNTAX:<O:P> </O:P>
Throw exception_obj
For example the following statement throw an ArgumentException explicitly.<O:P> </O:P>
Throw New ArgumentException("Exception") <O:P> </O:P>
<O:P>Example 1:</O:P>
<O:P>Imports System
Class MyClient
Public Shared Sub Main()
Try
Throw New DivideByZeroException("Invalid Division")
Catch e As DivideByZeroException
Console.WriteLine("Exception")
End Try
Console.WriteLine("LAST STATEMENT")
End Sub 'Main
End Class 'MyClient<O:P> </O:P></O:P>
<O:P><O:P></O:P></O:P> <O:P><O:P> Re-throwing an Exception <O:P> </O:P>
The exceptions, which we caught inside a catch block, can re-throw to a higher context
by using the keyword throw inside the catch block. The following program shows how to
do this. <O:P> </O:P>
<O:P>Example 2:</O:P>
<O:P>Imports System
Class [MyClass]
Public Sub Method()
Try
Dim x As Integer = 0
Dim sum As Integer = 100 / x
Catch e As DivideByZeroException
Throw
End Try
End Sub 'Method
End Class '[MyClass]
Class MyClient
Public Shared Sub Main()
Dim mc As New [MyClass]()
Try
mc.Method()
Catch e As Exception
Console.WriteLine("Exception caught here")
End Try
Console.WriteLine("LAST STATEMENT")
End Sub 'Main
End Class 'MyClient </O:P>
<O:P></O:P>
<O:P>Hope this clears your doubts. </O:P>
<O:P>Regards,
Shri</O:P></O:P></O:P>
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]