473,698 Members | 2,546 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 #1
20 3616
Cor
Hi Dragu,

If you are used to the possibilties from the

Try
Catch (multiples
End Try
Finally

And the nesting posibilities from that, you would not believe you could do
it with the "on error goto"

I hope this gives an idea?

Cor
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!

Nov 20 '05 #2
Hi,
I was a VB-programmer to and I was used to on error but now Try .. catch is
better.
With this statement you can catch all different types of exceptions and
perform a specific action for each one.
I hope this will be usefull for you
Regards
Valeria

"DraguVaso" <pi**********@h otmail.com> ha scritto nel messaggio
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 #3
* "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 #4
Cor
Hi Herfried,

That discussion was done before you was born

If you have problems with that, start studing Pascal, that was special made
for it.

:-)

Cor
Nov 20 '05 #5
* "Cor" <no*@non.com> scripsit:
That discussion was done before you was born

If you have problems with that, start studing Pascal, that was special made
for it.


LOOOOOOOL.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
I think is better only because in this way I can simply specify different
actions for each exception if you want and I never loved on error
statement...
a personal opinion maybe!
Valeria

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> ha scritto nel
messaggio 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 #7
* "Valeria" <va***@tiscali. it> scripsit:
I think is better only because in this way I can simply specify different
actions for each exception if you want and I never loved on error
statement...
a personal opinion maybe!


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

IMO, unstructured error handling is a nice feature in some cases, but
generally, structured error handling should be preferred.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8
Ok!! Thanks everybody!
I got on GotDotNet two nice related articles about it:
http://msdn.microsoft.com/library/en...t_errorhandlin
g.asp

http://msdn.microsoft.com/library/en...hExceptionsErr
orsInVisualBasi cNET.asp
"Valeria" <va***@tiscali. it> wrote in message
news:dk******** *************@n ews1.tin.it...
I think is better only because in this way I can simply specify different
actions for each exception if you want and I never loved on error
statement...
a personal opinion maybe!
Valeria

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> ha scritto nel
messaggio 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 #9
Cor
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
Nov 20 '05 #10

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
3028
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
2740
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
4449
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
2771
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
47994
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
2415
by: dick | last post by:
in the "try{throw}catch" structure, how the C++ code return the "type" thrown by a function?
0
5677
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
8678
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
9166
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6525
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
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.