Question about exceptions

G

Guest

Hello Group
I have a button click sub, which calles a function called 'send'
to send over a tcp connection. This function can call an
exception. If an exception occurs, I need to quit the button
click function. My problem is how do I propagate the
exception from the 'send' function, to the parent function
(the button click function).
Thanks (I have not done this sort of thing before)
(unless the way it to simply use return codes and test them,
like in api programming)
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Lawry said:
I have a button click sub, which calles a function called 'send'
to send over a tcp connection. This function can call an
exception. If an exception occurs, I need to quit the button
click function. My problem is how do I propagate the
exception from the 'send' function, to the parent function
(the button click function).

You don't have to. It will propagate automatically until it's caught.
 
G

Guest

You don't have to. It will propagate automatically until it's caught.

My question is this: if there is an exception in the nested sub, will it
return to the parent sub right away, or will it try to complete the
other lines in the sub first, e.g. if it was inside a for loop?
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Lawry said:
My question is this: if there is an exception in the nested sub, will it
return to the parent sub right away, or will it try to complete the
other lines in the sub first, e.g. if it was inside a for loop?

It will exit right away.
 
M

Michel Posseth [MCP]

it works through a so called chaining mechanism

Sub MethodA
Try
MethodB
catch ex as exception
'the error that took place in MethodC is handled in this method
'if there was no exception handler here the program will crash
End try
'all code here will run if the catch has no exit sub
end sub

Sub MethodB
MethodC
'all code here is never touched exit takes place at the exception origin
line
end sub


Sub MethodC
'''''''''' exception here """"""""
all code here is never touched exit takes place at exception line
end sub

This is the reasson why i have the opinion that rethrowing exceptions is
never valid for the sole reasson of throwing it to the next call level ( i
think it is foolish )
as the chaining mechanism will take care of it automaticly and much more
efficient with a lot more exception details
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top