Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

Silly question about Try Catch...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 11 Jul 2005 12:26 GMT
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.
adebaene@club-internet.fr - 11 Jul 2005 12:45 GMT
John a écrit :
> Hello I know this is extremely basic, I just want to make sure I got it right.
>
> is:
>
> try{}
> catch{}
This is not valid C++ : catch block must have an exception type
specification (see compiler error C2309). You must be confusing with C#
where this syntax is valid.

Arnaud
MVP - VC
Manny Silva - 11 Jul 2005 21:14 GMT
The way to make a catch block unrestrictive is to use the elipsis as the
parameter.  That is:

try{}
catch(...){}

that means catch anything that is thrown, no matter what it is.  This is
very useful if you need to perform some manual clean-up operation when an
exception is thrown... you can send the exception on with the throw command
without passing it a parameter... as such:

try{}
catch(...)
{
  // perform cleanup here
  throw;
}

but if you do:
try{}
catch(System::Exception* ex){}

then you are saying that you only want to catch exception that are derived
from System::Exception.  Any exception that is thrown that does not derive of
this object will not be caught in this exception (with managed code, all
exceptions should derive from System::Exception).

Or, perhaps you are refering to this type of syntax:

try{}
catch(System::Exception*){}

this says that you want to catch any exception that derives from
System::Exception, but you do not care to use the object

hope this helps

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.