473,734 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"on error goto" or "try catch"

Hi,

As a former VB-programmer I'm used to the "on error goto"-errorhandling. I
see that in actually all the VB.NET-samples I can fin people use the "Try -
catch"-errorhandling.

Which of the two is the best? Are there good reasons to use the Try-Catch?
Will the "on error goto" disapear in the future? Are there any logical
reasons to use trey-catch? Is it 'better' programming? etc etc :-)

I'm jsut more comfortable with the "on error goto", mostly because I'm used
to it I guess. Any help or reflectiosn regarding this subject would be nice!

Thanks in advance!
Nov 20 '05
20 3621
* "Cor" <no*@non.com> scripsit:
Brrrrrrrrrrrrrr rrrrrrrrrr
;-)
What is here the difference with a standarized try catch end try finally
solution?
There is no big difference.
Answer, I have to check the list with errornumbers, and need HKW to give me
a link for that.
\\\
Select Case Err.Number
Case err1, err2
...
Case err3
...
...
End Select
///


The sample above is VB6 code.

;->

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #11
Herfried,
for example when impementing a large algorithm, Although I may implement a large algorithm, I tend to implement it with
smaller routines, which helps avoid this problem, or at least it spreads the
problem out.

Of course one can have routines that are too small...

Just a thought
Jay

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bq******** *****@ID-208219.news.uni-berlin.de... * "Valeria" <va***@tiscali. it> scripsit:
I was a VB-programmer to and I was used to on error but now Try .. catch is better.


But: _Why_ exactly is it better? It's IMO better in some cases because it
leaves code more compact, but sometimes, for example when impementing a
large algorithm, it's very annoying because it will prevent the reader
from seeing the point of the code.

Just a thought.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #12
DraguVaso,
A year and a half or two years ago there were a couple big discussions on
this subject, I'm not sure how easy it would be to find those threads in
this newsgroup at http://groups.google.com...

I generally only use Try/Catch blocks where I have to use a try/catch block,
generally when I am managing a resource, for example a SqlConnection that I
need to be certain I close when I exit a routine. Or I cannot use a method
to avoid the exception (HashTable.Cont ains to see if the key exists before
using HashTable.Item to retrieve the item).

In .NET there is less of a need to include error handlers in every routine,
for example in Windows Forms applications you can set a global exception
handler that will effectively add a error handler to each of your event
handlers under the covers, this global exception handler can log the error
and allow you app to continue in a predictable manner.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For Windows Forms look at:
System.Windows. Forms.Applicati on.ThreadExcept ion event
Use AddHandler in your Sub Main before you call Application.Run .

For ASP.NET look at:
System.Web.Http Application.Err or event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomai n.UnhandledExce ption event
Use AddHandler in your Sub Main.

Hope this helps
Jay
"DraguVaso" <pi**********@h otmail.com> wrote in message
news:3f******** **************@ reader0.news.sk ynet.be...
Hi,

As a former VB-programmer I'm used to the "on error goto"-errorhandling. I
see that in actually all the VB.NET-samples I can fin people use the "Try - catch"-errorhandling.

Which of the two is the best? Are there good reasons to use the Try-Catch?
Will the "on error goto" disapear in the future? Are there any logical
reasons to use trey-catch? Is it 'better' programming? etc etc :-)

I'm jsut more comfortable with the "on error goto", mostly because I'm used to it I guess. Any help or reflectiosn regarding this subject would be nice!
Thanks in advance!

Nov 20 '05 #13
I say to hell with error handling, throw ( no pun intended ) caution to the
wind and simply put the following statement before any block of code.

On Error Resume Next ' Syntax for ( who gives a $h*t )
ROTFLMAO

OHM


Cor wrote:
Brrrrrrrrrrrrrr rrrrrrrrrr

What is here the difference with a standarized try catch end try
finally solution?

Answer, I have to check the list with errornumbers, and need HKW to
give me a link for that.
\\\
Select Case Err.Number
Case err1, err2
...
Case err3
...
...
End Select
///


Cor


Best Regards - OHMBest Regards - OHM On**********@BT Internet.Com
Nov 20 '05 #14
Cor
Hi OHM

Is that the same as?

sub blabla
try
do your statements
catch
end try
end sub

Cor

On Error Resume Next ' Syntax for ( who gives a $h*t )
ROTFLMAO

OHM


Cor wrote:
Brrrrrrrrrrrrrr rrrrrrrrrr

What is here the difference with a standarized try catch end try
finally solution?

Answer, I have to check the list with errornumbers, and need HKW to
give me a link for that.
\\\
Select Case Err.Number
Case err1, err2
...
Case err3
...
...
End Select
///


Cor


Best Regards - OHMBest Regards - OHM On**********@BT Internet.Com

Nov 20 '05 #15
Almost, just that in scenario Resume Next, you just carry one regardless.

Cheers - OHM

Cor wrote:
Hi OHM

Is that the same as?

sub blabla
try
do your statements
catch
end try
end sub

Cor

On Error Resume Next ' Syntax for ( who gives a $h*t )
ROTFLMAO

OHM


Cor wrote:
Brrrrrrrrrrrrrr rrrrrrrrrr

What is here the difference with a standarized try catch end try
finally solution?

Answer, I have to check the list with errornumbers, and need HKW to
give me a link for that.

\\\
Select Case Err.Number
Case err1, err2
...
Case err3
...
...
End Select
///

Cor


Best Regards - OHMBest Regards - OHM On**********@BT Internet.Com


Best Regards - OHMBest Regards - OHM On**********@BT Internet.Com
Nov 20 '05 #16
Cor
Hi OHM

With this also or I see something totaly wrong
Almost, just that in scenario Resume Next, you just carry one regardless.

sub blabla
try
do your statements
catch
end try
end sub

Nov 20 '05 #17
* "Cor" <no*@non.com> scripsit:
Brrrrrrrrrrrrrr rrrrrrrrrr

What is here the difference with a standarized try catch end try finally
solution?


Why is 'Try...Catch' standardized and 'On Error...' not standardized?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #18
* "Cor" <no*@non.com> scripsit:
With this also or I see something totaly wrong


Don't you have the help files installed?!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #19
Cor
Herfried,
What is here the difference with a standarized try catch end try finally
solution?


Why is 'Try...Catch' standardized and 'On Error...' not standardized?


That one I should not have used, I just made a message in the thread from
Ivan Weiss that in my opinion it looks if people want to make from VB.net
something as C.

I did not write it but with those sentence you know I mean things as
dim a as string = (Cint(Dbl(8/1)*2)).tostring

But one of the things I alway deny in every language is a goto and an alter.
(Altering is changing pointers, the first commando like that was branch
conditional register)

The "case select" was in past also a kind of goto so I did not want that
either, although the newones are no problem anymore for me.

I never understood how to handle that Onerror goto from VB while giving the
code also a good description value.

Cor

Nov 20 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3890
by: Meya | last post by:
Hi, when I hit my http://<domain name> site,I am getting this error msg: I have also installed my SSL cert on the IIS 5.0 ******************************** The page must be viewed over a secure channel Please try the following:
40
3038
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the goodness of Python whenever I talk with fellow developers, but I always hit a snag when it comes to discussing the finer points of the execution model (specifically, exceptions). Without fail, when I start talking with some of the "old-timers"...
9
1966
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual Basic .Net application. I have researched MSDN for help and found the example article 321900 (see below) and set up a test and everything works fine when I use SQL Server 2000 but when I modify the code and use data from Access 2000 using an...
1
2744
by: Francesc Guim Bernat | last post by:
Dear colleagues, i'm getting in troubles using one XML library with Visual Studio .NET and Xerces with Xalan. When i execute the code i get the next run time error: "Run-Time Check Failure #2 - Stack around the variable 'resolver' was corrupted." Looking on internet i've seen that the compiler, if you're running your
6
4453
by: bill salkin | last post by:
I setup a "Try..." block and attempted to open a non- existant database. It went to the second "catch" not the first. What is the proper "catch" clause for this specific case? TIA, Bill
1
2773
by: pbd22 | last post by:
hi. for some reason i am not able to navigate the dom. i keep getting the 'no properties' error but i think i am doing everything right. this is an XML response from an AJAX call. The ajax method to call the server code looks like this. i am passing a cookie as a parameter:
11
47999
by: Maxwell2006 | last post by:
Hi, I know that this is not a good practice, but I wonder do we have "on error resume next" in C#? Thanks,
7
2421
by: dick | last post by:
in the "try{throw}catch" structure, how the C++ code return the "type" thrown by a function?
0
5681
by: Ismail Fatih Yýldýrým | last post by:
I modified the RSACSPSample from MSDN to try out a simple commutative encryption model using RSA encryption but when i run the progrem the first encryption command works but during the second encryption command (line : encryptedData2 = RSAE...) i get a "Key not valid for use in specified state." exception error even though i provide a valid second key to encrypt it. How can i overcome this error and get double encryption to work ? The...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.