473,378 Members | 1,493 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,378 software developers and data experts.

catch with no explicit object

class excep
{

};

int main ( )
{
try
{
throw excep ();
}
catch (excep)
{

}
}

Is the catch (excep) equivalent to
catch (excep& e) or
catch (excep e)

Also is it possible to get an handle to the excep object in
catch(excep)

Sep 22 '06 #1
4 1440
Ninan wrote:
class excep
{

};

int main ( )
{
try
{
throw excep ();
}
catch (excep)
{

}
}

Is the catch (excep) equivalent to
catch (excep& e) or
catch (excep e)
Do you see the ampersand there? So, why ask? Is 'foo(int)'
equivalent to 'foo(int& a)' or 'foo(int a)'?
Also is it possible to get an handle to the excep object in
catch(excep)
Yes. Name that object and use the name.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 22 '06 #2
Ninan wrote:
class excep
{

};

int main ( )
{
try
{
throw excep ();
}
catch (excep)
{

}
}

Is the catch (excep) equivalent to
catch (excep& e) or
catch (excep e)
It is not equivalent to either of them, but it is nearly so to the
latter. The difference is that the latter creates a local copy of the
exception that you can access. It's like if you call a function but
don't name a parameter:

void Foo( int ) { /*...*/ }

Foo() can only be called with an int parameter (or something implicitly
convertible to an int), but within Foo, the programmer has no access to
what the int value was.
Also is it possible to get an handle to the excep object in
catch(excep)
See above. But you should generally catch by *const reference*. See
these FAQs:

http://www.parashift.com/c++-faq-lit....html#faq-17.7
http://www.parashift.com/c++-faq-lit....html#faq-18.1

Cheers! --M

Sep 22 '06 #3
Victor Bazarov wrote:
Ninan wrote:
class excep { };

int main ( ) {
try {
throw excep ();
}
catch (excep) {
}
}
Also is it possible to get an handle to the excep object in
catch(excep)

Yes. Name that object and use the name.
Well, that wasn't really the solution he was looking for I guess. It
must be
the last created excep object. So add a global excep* lastinstance and
set that in excep::excep(excep const&). Then you only need to get
*lastinstance. I mean, he wouldn't asked for the obvious solution if
that would work, now would he?

Michiel.

Sep 22 '06 #4
Mi*************@tomtom.com wrote:
Victor Bazarov wrote:
>Ninan wrote:
>>class excep { };

int main ( ) {
try {
throw excep ();
}
catch (excep) {
}
}
>>Also is it possible to get an handle to the excep object in
catch(excep)

Yes. Name that object and use the name.

Well, that wasn't really the solution he was looking for I guess. It
must be
the last created excep object.
Last created by whom? By a destructor of some object being disposed
of during stack unwinding? Nobody prevents me from saying

excep *myexcep = new excep;

anywhere. It doesn't cause stack unwinding to fail.
So add a global excep* lastinstance
How many global data does your code usually have, per a kiloLOC?
Just curious, I guess.
and
set that in excep::excep(excep const&). Then you only need to get
*lastinstance. I mean, he wouldn't asked for the obvious solution if
that would work, now would he?
Don't put words into somebody else's mouth, don't assume people know
what they are doing, don't assume if something's obvious to you, it is
to everybody.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 22 '06 #5

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

Similar topics

6
by: Tilfried Weissenberger | last post by:
Hi, I am a bit confused as to what the FINALLY block is meant for. What's the difference between: this.Cursor = Cursors.WaitCursor; try { //do some stuff } catch { //handle exception }...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
12
by: Doug Hill | last post by:
Please, Microsoft, update Option Explicit Option Strict barks at late binding. We love late binding. So Option Strict flags too many things. Option Explicit is misleading. It allows Dim...
0
by: Gene Hubert | last post by:
I'm trying to catch the KeyUp event in textbox of a DataGrid. I'm picking up the keydown and keypress events ok, but not keyup. Can anyone see what is wrong with this code. I been fighting with...
34
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader...
3
by: Steven T. Hatton | last post by:
Has anybody here used explicit instantiation of templates? Has it worked well? Are there any issues to be aware of? -- NOUN:1. Money or property bequeathed to another by will. 2. Something...
13
by: 7stud | last post by:
To the developer: 1) I went to the pyparsing wiki to download the pyparsing module and try it 2) At the wiki, there was no index entry in the table of contents for Downloads. After searching...
9
by: SMH | last post by:
Hi, I am making the transition from VB to C# I am struggling to get my try/catch to work. For some reason, the exception is not caught. My code is below, any help will be much appreciated. ...
5
by: subramanian100in | last post by:
In the standard library vector, the ctor explicit vector::vector(size_type __n) is declared as explicit. I am unable to get the reason for it being declared as explicit. Kindly clarify with an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.