HighTechTalks DotNet Forums  

Silly Try Catch question...

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss Silly Try Catch question... in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
John
 
Posts: n/a

Default Silly Try Catch question... - 07-11-2005 , 07:32 AM






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.


Reply With Quote
  #2  
Old   
Peter van der Goes
 
Posts: n/a

Default Re: Silly Try Catch question... - 07-11-2005 , 09:10 AM







"John" <John (AT) discussions (DOT) microsoft.com> wrote

Quote:
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.

System.Exception is the base class for all exception types, therefore not
restrictive. To find out why your try catch blocks should always use a
parameter of type Exception (or subclass thereof), I suggest you look into
the important properties shared by these classes, such as Message (a string
containing a readable description of the raised exception).

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.




Reply With Quote
  #3  
Old   
Jay B. Harlow [MVP - Outlook]
 
Posts: n/a

Default Re: Silly Try Catch question... - 07-11-2005 , 09:28 AM



John,
In addition to the other comments.

For C# & VB.NET code both are the same, as both languages only support
throwing exceptions that inherit from System.Exception.

However! If you call another language that allows you to throw exceptions
that do not derive from System.Exception will cause the two statements to be
semantically different.

For details see:

http://msdn.microsoft.com/library/de...pspec_8_10.asp

Hope this helps
Jay

"John" <John (AT) discussions (DOT) microsoft.com> wrote

Quote:
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.




Reply With Quote
  #4  
Old   
John
 
Posts: n/a

Default Re: Silly Try Catch question... - 07-11-2005 , 09:57 AM



Thanks!

Very helpful

JT.

"Jay B. Harlow [MVP - Outlook]" wrote:

Quote:
John,
In addition to the other comments.

For C# & VB.NET code both are the same, as both languages only support
throwing exceptions that inherit from System.Exception.

However! If you call another language that allows you to throw exceptions
that do not derive from System.Exception will cause the two statements to be
semantically different.

For details see:

http://msdn.microsoft.com/library/de...pspec_8_10.asp

Hope this helps
Jay

"John" <John (AT) discussions (DOT) microsoft.com> wrote in message
news:BF5F960E-3B48-48DC-ABC8-EC9227B185DC (AT) microsoft (DOT) 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.
|




Reply With Quote
  #5  
Old   
John
 
Posts: n/a

Default Re: Silly Try Catch question... - 07-11-2005 , 10:05 AM



Actually I am glad I posted this on

"microsoft.public.dotnet.academic" and on:
"microsoft.public.dotnet.general"

as I now discovered I got the wrong answer on
"microsoft.public.dotnet.general"

check it out:

http://msdn.microsoft.com/newsgroups...=en-us&m=1&p=1

Reply With Quote
  #6  
Old   
Alvin Bruney [MVP - ASP.NET]
 
Posts: n/a

Default Re: Silly Try Catch question... - 07-13-2005 , 01:51 PM



no, the reply to your thread is entirely correct in .net.general. if you
need more detailed information, have a read of jeffrey richters book -
applied framework programming

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
"John" <John (AT) discussions (DOT) microsoft.com> wrote

Quote:
Actually I am glad I posted this on

"microsoft.public.dotnet.academic" and on:
"microsoft.public.dotnet.general"

as I now discovered I got the wrong answer on
"microsoft.public.dotnet.general"

check it out:

http://msdn.microsoft.com/newsgroups...=en-us&m=1&p=1



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.