| | |
Try-Catch feature for VB6, VBA, VBScript
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 6
Reputation:
Solved Threads: 0
Hi Everyone,
This feauture enables to use "Try" exception handling in VB programs like VB.net Try-Catch statement.
http://sites.google.com/site/truetryforvisualbasic/
I think it's a new way of exception handling in VB 4,5,6, VBA and VBScript.
I'm waiting for opinions.
This feauture enables to use "Try" exception handling in VB programs like VB.net Try-Catch statement.
http://sites.google.com/site/truetryforvisualbasic/
I think it's a new way of exception handling in VB 4,5,6, VBA and VBScript.
I'm waiting for opinions.
Last edited by RobEin; Oct 27th, 2009 at 9:33 am.
•
•
Join Date: Mar 2009
Posts: 913
Reputation:
Solved Threads: 167
0
#2 Oct 27th, 2009
I believe you have posted this before and now that you have actually asked for opinions, here we go.
This is not like VB.NET's Try, Catch, Finally as you explicity tell the compiler to ignore errors (On Error Resume Next or On Error GoTo 0)...
The following is VB.NET code with the proper basic Try, Catch, Finally, End Try code in a form load sub.
and while some may think it would be nice to have such error handling in vb6, one can achieve the same with standard vb6 error handling if one thinks about it.
Good Luck
This is not like VB.NET's Try, Catch, Finally as you explicity tell the compiler to ignore errors (On Error Resume Next or On Error GoTo 0)...
The following is VB.NET code with the proper basic Try, Catch, Finally, End Try code in a form load sub.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Catch ex As Exception Finally End Try End Sub End Class
and while some may think it would be nice to have such error handling in vb6, one can achieve the same with standard vb6 error handling if one thinks about it.
Good Luck
Last edited by vb5prgrmr; Oct 27th, 2009 at 9:39 am.
If anyone has helped you solve your problem, please mark your thread as solved.
Thanks
Thanks
•
•
Join Date: Oct 2009
Posts: 6
Reputation:
Solved Threads: 0
0
#3 Oct 27th, 2009
My post was sent for the old VB 4,5,6 and not for VB.net.
I know the syntax of VB.net Try-Catch statement of course and I wrote that my way similar not same.
But it can achieve the almost same essentially.
I realy tell the VB compiler to ignore errors between 'On Error Resume Next' and 'On Error Goto label'.
Do You know other or better way in old VB, VBA, VBScript?
May I ask You, what code do You use for structured exception handling in VB?
I know the syntax of VB.net Try-Catch statement of course and I wrote that my way similar not same.
But it can achieve the almost same essentially.
I realy tell the VB compiler to ignore errors between 'On Error Resume Next' and 'On Error Goto label'.
Do You know other or better way in old VB, VBA, VBScript?
May I ask You, what code do You use for structured exception handling in VB?
Last edited by RobEin; Oct 27th, 2009 at 11:59 am.
•
•
Join Date: Mar 2009
Posts: 913
Reputation:
Solved Threads: 167
0
#4 Oct 27th, 2009
I use the standard error handling scheme but then again I also code defensivly...
The basics for debugging are as follows...
This way I know where, #, and description while designing. Once I have finished the code and test the application and know where and what errors might occur, I adjust the code to a more defensive posture.
An example of this might be installing a dir check for a file to see if it exists before trying any type of file operation.
Then there are some errors that just cannot be accounted for like doing a recursive dir search on a hard drive from the root and the dir function coming across a *.sys file and an example on how I get around that can be found here...
http://www.tek-tips.com/viewthread.c...&val=1,1533303
So, if you can see that example the code is not "do this, do that, do the other". It is more like "If I can do this then do it else try to do something else" and so on.
Good Luck
The basics for debugging are as follows...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Option Explicit Private Sub Form_Load() On Error GoTo Form_LoadError Exit Sub Form_LoadError: MsgBox "Form_Load " & Err.Number & ":" & Err.Description End Sub
This way I know where, #, and description while designing. Once I have finished the code and test the application and know where and what errors might occur, I adjust the code to a more defensive posture.
An example of this might be installing a dir check for a file to see if it exists before trying any type of file operation.
Then there are some errors that just cannot be accounted for like doing a recursive dir search on a hard drive from the root and the dir function coming across a *.sys file and an example on how I get around that can be found here...
http://www.tek-tips.com/viewthread.c...&val=1,1533303
So, if you can see that example the code is not "do this, do that, do the other". It is more like "If I can do this then do it else try to do something else" and so on.
Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.
Thanks
Thanks
•
•
Join Date: Oct 2009
Posts: 6
Reputation:
Solved Threads: 0
0
#7 Nov 7th, 2009
The finally feature is optional and not required to catch an expected exception (Finally does not exist in C++, for example.).
But it's a possible solution for Finally in VB-Try-Catch:
The difference between VB-Try-Finally and other langugage Try-Finally:
If Exit Sub-Function-Property is used in Select-Case statement, the "Finally" section will not be executed.
There may be similarly problems even with Exit For-Do or GoTo or Return statements.
But it's a possible solution for Finally in VB-Try-Catch:
With New Try: On Error Resume Next
Debug.Print 1 / 0 'Division by zero
.Catch: On Error GoTo 0: Select Case .Number
Case 11
MsgBox "Division by zero error."
Case Else
MsgBox Err.Description
End Select
[...Finally-code...]
End WithIf Exit Sub-Function-Property is used in Select-Case statement, the "Finally" section will not be executed.
There may be similarly problems even with Exit For-Do or GoTo or Return statements.
Last edited by RobEin; Nov 7th, 2009 at 2:45 am.
![]() |
Similar Threads
- Is it VB6 or VBA? (DaniWeb Community Feedback)
- Textbox: On Copy... (VBA in AC2003) (Visual Basic 4 / 5 / 6)
- Declaring multidimensional array in VBA (Visual Basic 4 / 5 / 6)
- Introduce myself (Community Introductions)
- problem connection vb6 & crystal report 11 (Visual Basic 4 / 5 / 6)
- VB6 or VBA - Copy table contents from one database to identical database (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Need Some Help :)
- Next Thread: Reading from a database
Views: 1089 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





