473,406 Members | 2,867 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,406 software developers and data experts.

Silly question about Try Catch...

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.
Nov 17 '05 #1
4 940


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

Nov 17 '05 #2


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

Nov 17 '05 #3
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
Nov 17 '05 #4
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
Nov 17 '05 #5

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...
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{}
0
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{}
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{}
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.