473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Silly Try Catch question...

Hello I know this is extremely basic, I just want to make sure I got it right.

is:

try{}
catch{}

the same as

try{}
catch(System.Exception e){}

I mean if I am not using the reference to the exception then I should simply
use
catch{} ? or is catch(System.Exception){} somehow more restricted on what
it catches than simply catch{}?

Thanks in advance

JT.

Jul 22 '05 #1
3 1394
"catch(System.Exception e)"

will catch *all* .NET exceptions.

simply "catch" will also catch exceptions not based on System.Exception,
that is not CLS compliant exceptions which could be thrown by native code or
managed c++.

If you do not need a reference to the exception use
"catch(System.Exception)".

But you always should only catch the most specific exception which you are
expecting for example FormatException when you are parsing something and so
on, this makes sure you are not swallowing heavy bugs.
"John" <Jo**@discussions.microsoft.com> schrieb im Newsbeitrag
news:D2**********************************@microsof t.com...
Hello I know this is extremely basic, I just want to make sure I got it right.
is:

try{}
catch{}

the same as

try{}
catch(System.Exception e){}

I mean if I am not using the reference to the exception then I should simply use
catch{} ? or is catch(System.Exception){} somehow more restricted on what
it catches than simply catch{}?

Thanks in advance

JT.

Jul 22 '05 #2
Thanks!

very helpful.

"cody" wrote:
"catch(System.Exception e)"

will catch *all* .NET exceptions.

simply "catch" will also catch exceptions not based on System.Exception,
that is not CLS compliant exceptions which could be thrown by native code or
managed c++.

If you do not need a reference to the exception use
"catch(System.Exception)".

But you always should only catch the most specific exception which you are
expecting for example FormatException when you are parsing something and so
on, this makes sure you are not swallowing heavy bugs.
"John" <Jo**@discussions.microsoft.com> schrieb im Newsbeitrag
news:D2**********************************@microsof t.com...
Hello I know this is extremely basic, I just want to make sure I got it

right.

is:

try{}
catch{}

the same as

try{}
catch(System.Exception e){}

I mean if I am not using the reference to the exception then I should

simply
use
catch{} ? or is catch(System.Exception){} somehow more restricted on what
it catches than simply catch{}?

Thanks in advance

JT.


Jul 22 '05 #3
pam


"John" wrote:
Thanks!

very helpful.

"cody" wrote:
"catch(System.Exception e)"

will catch *all* .NET exceptions.

simply "catch" will also catch exceptions not based on System.Exception,
that is not CLS compliant exceptions which could be thrown by native code or
managed c++.

If you do not need a reference to the exception use
"catch(System.Exception)".

But you always should only catch the most specific exception which you are
expecting for example FormatException when you are parsing something and so
on, this makes sure you are not swallowing heavy bugs.
"John" <Jo**@discussions.microsoft.com> schrieb im Newsbeitrag
news:D2**********************************@microsof t.com...
Hello I know this is extremely basic, I just want to make sure I got it

right.

is:

try{}
catch{}

the same as

try{}
catch(System.Exception e){}

I mean if I am not using the reference to the exception then I should

simply
use
catch{} ? or is catch(System.Exception){} somehow more restricted on what
it catches than simply catch{}?

Thanks in advance

JT.


Oct 4 '05 #4

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

Similar topics

1
by: ShaneB | last post by:
Hello all! To test my app's exception handling, I've coded a call to DNS.BeginResolve() with an intentionally bad host name. When I put the code in a try/catch block, all works fine and a...
5
by: Jacek Dziedzic | last post by:
Hi! In my main() function I have a last-resort exception construct that looks like this: int main() { try { // ... program code }
15
by: Jon Skeet | last post by:
I've been briefly musing on what is probably a pretty silly idea, but one which would no doubt benefit from being discussed and thoroughly shot down in flames rather than being allowed to fester in...
4
by: John | last post by:
Hello I know this is extremely basic, I just want to make sure I got it right. is: try{} catch{} the same as try{}
13
by: Woody Splawn | last post by:
I have a try catch statement in a fucntion that is supposed to return a true or a false My code looks like this: Try mySqlConnection.Open() Dim Da1 As New SqlDataAdapter("Select JnlType,...
7
by: Tiraman | last post by:
Hi , I am using allot the try catch in my code and the question is if it is good ? it will decrease my performance ? one more question
9
by: Michael MacDonald | last post by:
Does someone have a good site I can visit or explain the use of Try" and Catch foe exception/error handling. What is the logic behind this command and maybe an example would be great!!!! Mike_Mac...
3
by: John | last post by:
Hello I know this is extremely basic, I just want to make sure I got it right. is: try{} catch{} the same as try{}
23
by: pigeonrandle | last post by:
Hi, Does this bit of code represent complete overkill?! try { //create a treenode TreeNode tn = new TreeNode(); //add it to a treeview tv.Nodes.Add(tn);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.