home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2916
Discussions: 188,379, Posts: 2,243,457, Members: 232,607
Old September 27th, 2002, 12:13 AM   Digg it!   #1 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,018
Try, Catch, Finally

Ok with vb.net they finally have some error handling and one thing I'm unsure of...

I understand try and catch, but what' the deal with finally?

What's the difference between...

Try
DoSomeStuff
Catch
'doh that broke
MsgBox "It broke ya idiot"
Finally
Do some other stuff
End Try

AND....

Try
DoSomeStuff
Catch
'doh that broke
MsgBox "It broke ya idiot"
End Try


Do some other stuff

whats the diff of putting it into the finally, and leaving it out?

According to MSDN Finally runs regardless of the error..


Maybe if there's a fatal error, put code in the finally to close gracefully!?!

vass0922 is online now   Reply With Quote
Old September 27th, 2002, 03:54 PM     #2 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
Well, in Java you can have multiple catch blocks for different exceptions; the finally block runs even if you don't provide a catch block for an exception that gets thrown, which means that you can clean up before the method crashes out on you. Maybe this applies to VB.NET?

strangerstill is offline   Reply With Quote
Old September 27th, 2002, 04:04 PM     #3 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,018
Ohhhhh
So its an Else for exception handling

Yup that sounds right.. I was wondering when the java folk were going to swing by and see it, I knew java had true exception handling

Thanks!!

and just so I understand it, if I create a function and I Throw an exception, it should catch it from the calling procedure correct?
I'm assuming yes, but I never did get into the exception thing

vass0922 is online now   Reply With Quote
Old September 27th, 2002, 04:21 PM     #4 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
Yeah...I think so. All I know about exceptions is how to catch them (and I probably wouldn't even know *that* if the Java compiler didn't scream at you whenever you write code that leaves out whatever catch blocks it thinks you need). But yeah, when you throw an exception inside a function, it immediately exits that function and transfers control to the calling function; if the calling statement was in a try block, it looks for a catch statement and if it finds one it runs that block and then the finally block, otherwise it either re-throws the exception or ends the program or thread. Hopefully this makes some sense!
strangerstill is offline   Reply With Quote
Old September 27th, 2002, 04:26 PM     #5 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,018
piece o' cake
Although from what I understand (at least with vb.net, but assuming other languages would as well)
The application will still attempt to climb up teh call stack looking for a catch before fully exiting.. so may have to give that a test to see if it actually works

This app I'm writing makes calls out to network shares, so I'm gonna have to make a couple catches looking for network problems.. and for better error handling I may have to throw some exceptions down below in the stack..
Will give it a shot
vass0922 is online now   Reply With Quote
Old September 30th, 2002, 02:25 AM     #6 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to zskillz
i have found it helpful to use the catch area to print a stack trace of the error if there is an error actually caught. there have been times when data that I used later in the program wasn't what I expected, but I never had a problem with running the code... then I put the error/stacktrace print in the catch area and *poof* I realize that there is an error occuring, but it is not a fatal error. good luck
-Z
zskillz is offline   Reply With Quote
Old September 30th, 2002, 02:33 AM     #7 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
What I understand of it, finally is to do something regardless if an exception occured. I guess it would be useful if your catch block did something closed a form. Say you had a connection open, and maybe you wanted it to close, then I guess you could put it in the finally.

I never use it.
Creosote is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2884)
The United States Debt (20)
Looks like Burris will get his Sena.. (8)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Titan quest and Immortal Throne, an.. (17)
Recent Discussions
Help with an Ati Radeon HD 4850.. (24)
Install Problem for Windows Def.. (0)
New Build ( Finally ) (1)
dual monitors wont boot (0)
Folderchat Weekday thread (439)
MSN Hotmail Down??? (7)
Laptop waking up itself (0)
CPU wont boot (3)
Best digital camera for under 2.. (13)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:30 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28