|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
error handlewhat is the best way to handle runtime error for VB.net. back on VB6, I
normally used On error goto handle_err ..... handle_err: .... Under VB.net, is this still a good method? thanks. Try/Catch blocks.
Show quoteHide quote "GK" <G*@discussions.microsoft.com> wrote in message news:8978175E-92A4-4759-B416-74F42BB26CC7@microsoft.com... > what is the best way to handle runtime error for VB.net. back on VB6, I > normally used > On error goto handle_err > .... > handle_err: > ... > > Under VB.net, is this still a good method? thanks. > GK wrote:
> what is the best way to handle runtime error for VB.net. back on VB6, I I guess it depends on the error...> normally used > On error goto handle_err > .... > handle_err: > ... > > Under VB.net, is this still a good method? thanks. If the runtime errors you are getting are unhandled exceptions, put the code that causes them into a Try...Catch block. Example: try sub_that_causes_exception() catch e as exception 'you actually catch anything that inherits from System.Exception, and then even have different catches for different types of exceptions, if your "tried" code could cause more than 1 kind of exception. do_error_handling() ' end 'code may have small syntax errors ;) If you want to THROW an exception then: if some_variable = bad_value then throw New BadValueException 'Assumes that BadValueException is a defined class end if I'd suggest looking up on MSDN.com more on exception handlinging in VB.NET. There's a lot more to it than what I just described. Ijust gave the absolute basics. "GK" <G*@discussions.microsoft.com> schrieb: I am sure that somebody will disagree, but I'd say yes, it's still a good > what is the best way to handle runtime error for VB.net. back on VB6, I > normally used > On error goto handle_err > .... > handle_err: > ... > > Under VB.net, is this still a good method? method when it is used correctly. Especially for code migrated from VB6 it's the way to go without completely rewriting code. However, check out 'Try...Catch...End Try' and 'Throw'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> |
|||||||||||||||||||||||