home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Try, Catch, Finally

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2323
Discussions: 200,942, Posts: 2,379,282, Members: 246,304
Old September 27th, 2002, 12:13 AM   Digg it!   #1 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
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 offline   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)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
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
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
vass0922 is offline   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)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
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 offline   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
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2916)
Hackers global warming emails (5)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Wireless Televisions. (9)
California Passes Anti-Flat-HDTV Le.. (43)
Regular Build (6)
Is the PSU I received dead? (11)
HIS HD5770 graphic card question (15)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
Recent Discussions
Asus P4G8X Mobo (4)
screen resolution vs monitor size (2)
Wireless Televisions. (9)
radeon x850xt platinum & shader 3 (4)
sms storage to PC (0)
Regular Build (6)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Is the PSU I received dead? (11)
Have you switched yet? (85)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Fire in DVD (2)


All times are GMT -4. The time now is 03:22 PM.
TechIMO Copyright 2009 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