|
-
Apr 9th, 2006, 02:10 PM
#1
Thread Starter
Lively Member
[RESOLVED] Structured Error Handling question
I did an exercise and lesson about structured error handling yesterday.
I don't see the point in the "Finally" clause. Wouldn't code placed after the "End Try" do the same thing, or did I miss something?
Tom
-
Apr 9th, 2006, 03:01 PM
#2
Re: Structured Error Handling question
The code in the finally part gets run whether the code errors or not.
-
Apr 9th, 2006, 06:44 PM
#3
Re: Structured Error Handling question
As Merrion says, the contents of the Finally block gets executed under all circumstances. Have a look at this example:
VB Code:
Try
'Open database connection.
'Retrieve data.
Catch
'Notify user of error.
'Exit method.
Finally
'Close database connection.
End Try
In this case, if you didn't have a Finally block and an exception is thrown then the database connection wouldn't be closed. Finally is usually used for things like closing files, connections, etc. that must be done regardless of the circumstances. The Finally block will still be executed even if a Return statement has been executed, or even if the form or application has been closed. There is no other way to ensure that.
Last edited by jmcilhinney; Apr 9th, 2006 at 07:56 PM.
-
Apr 9th, 2006, 07:54 PM
#4
Re: Structured Error Handling question
 Originally Posted by jmcilhinney
The Finally block will still be executed even if a Return statement has been executed, or even if the form or application has been closed. There is no other way to ensure that.
THANK YOU! I've been trying to get SOMEONE to tell me the reason for the finaly, and that makes sense. This is the first time anyone has been able to explain that well enough that I get it.
-tg
-
Apr 9th, 2006, 09:31 PM
#5
Thread Starter
Lively Member
Re: Structured Error Handling question
The Finally block will still be executed even if a Return statement has been executed, or even if the form or application has been closed. There is no other way to ensure that.
Thanks - the lesson I have didn't make that point at all. - Tom
-
Apr 9th, 2006, 09:32 PM
#6
Thread Starter
Lively Member
Re: Structured Error Handling question
-
Apr 9th, 2006, 09:45 PM
#7
Re: Structured Error Handling question
 Originally Posted by Tom951
Where is Royston Vasey?
It's the fictional town in which the English comedy series "The League of Gentlemen" is set. Those who've seen it should also understand the "Egregious" reference in my profile. Those who haven't seen it should.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|