Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Use the Err.GetException method to create custom exceptions

Total Hit ( 3022)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The Visual Basic .NET Err.Raise method and the Throw command are (partially) compatible. For example, you can use a Try...End Try block to catch an error raised with the Err.Raise method, and you can use an On Error Resume Next and the Err object to neutralize and inspect an exception object created by the Throw command. The old and the new error trapping mechanisms don't coexist well, though, and there are a few limitations. For example, you can't have an On Error Resume Next statement and a Try...End Try block in the same procedure.

To assist you in porting existing applications to VB.NET, the Err object has been extended with the new GetException method, which returns the Exception object that corresponds to the current error. This feature lets you preserve old-style error handlers in those procedures that don't lend themselves to an easy porting to the new syntax. This new method also enables such procedures them to correctly throw an exception object to their caller, where the exception can be processed using a Try block as usual:

Click here to copy the following block
Sub OldStyleErrorHandlerProc()
  On Error Goto ErrorHandler

  ' Cause a division by zero error,
  Dim x, y As Integer
  y = 1 \ x
  Exit Sub

ErrorHandler:
  ' Add here clean up code as necessary.
  ' ...
  ' Then report the error to the caller as an Exception object.
  Throw Err.GetException
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.