try catch的问题!!!

do
try
strline=objreader.readline
intlinecount=intlinecount+1
catch e as endofstreamexception
messagebox.show(e.message)
exit do
finally
strdata=strdata&strline&vbcrlf
end
loop while strline<>nothing

请问当执行到EXIT DO时将跳出DO WHILE 那么finally还执行吗???
---------------------------------------------------------------

finally是在TRY中最后必须执行的代码,如果需要exit do
strdata=strdata&strline&vbcrlf 就不放在TRY中
---------------------------------------------------------------

Yes.

You can use the Try...Catch...Finally statements for structured exception handling. This allows you to execute a particular block of statements if a specified exception occurs while your code is running. When this happens, the code is said to throw the exception, and you catch it with the appropriate Catch statement.

Execution enters the Try...Catch...Finally block with the statement block following the Try statement. If Visual Basic completes this block without an exception being generated, it looks for the optional Finally statement at the end. If you have supplied the Finally statement, Visual Basic executes the statement block following it. In any case, control is then transferred to the statement following the End Try statement.

If an exception occurs, Visual Basic examines the Catch statements in the order they appear within Try...Catch...Finally. If it finds a Catch statement that handles the generated exception, it executes the corresponding statement block. When it has finished executing the Catch block, it executes the Finally block if it is present. Execution then proceeds to the statement following the End Try statement.

---------------------------------------------------------------

执行的
---------------------------------------------------------------

执行,不过可以跳出

Published At
Categories with Web编程
Tagged with
comments powered by Disqus