471,076 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Handling Exception

Hello All,
I have a question about exception handling. It seems that you can
declare an exception class within another class as follow.
---------------------------------
class Array
{
---
---
---
class outofbound {};

---
};
---------------------------------
Then you can use it in a "try" "throw" "catch" syntax in for instance
the main function as
---------------------------------
int main()
{
-----
-----
try
{
----
if (problem)
throw outofbound();
----
----
}
catch(Array::outofbound)
{
----
}
----------------------------------
It seems to work fine. But what I do not understand properly is the
following thing. If there is a problem an outofbound object is being
made with the constructor outofbound() and thrown and then caught by
the catch ?? If I am right, but then it seems (at least to me) that
that object has no name. I have expected something more like

catch(Array:: outofbound myoutofbound_object_name)

My question is: Is the name left away just as you can leave away the
name of a function argument at a function prototype. Or is the object
named after its class name ??
Many thanks in advance.

Robert Huang Foen Chung

Jul 23 '05 #1
1 1296
TJ

wo*********@yahoo.com wrote:
Hello All,
I have a question about exception handling. It seems that you can
declare an exception class within another class as follow.
---------------------------------
class Array
{
---
---
---
class outofbound {};

---
};
---------------------------------
Then you can use it in a "try" "throw" "catch" syntax in for instance
the main function as
---------------------------------
int main()
{
-----
-----
try
{
----
if (problem)
throw outofbound();
----
----
}
catch(Array::outofbound)
{
----
}
----------------------------------
It seems to work fine. But what I do not understand properly is the
following thing. If there is a problem an outofbound object is being
made with the constructor outofbound() and thrown and then caught by
the catch ?? If I am right, but then it seems (at least to me) that
that object has no name. I have expected something more like

catch(Array:: outofbound myoutofbound_object_name)

My question is: Is the name left away just as you can leave away the
name of a function argument at a function prototype. Or is the object
named after its class name ??
Many thanks in advance.

Robert Huang Foen Chung


There is nothing wrong (nor it's better this way) in omitting the
variable name here. Of course, you wont be able to access the
information passed through the exception object. I don't see any use
of such exception handlers although it is semantically correct.
-TJ

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Hans-Joachim Widmaier | last post: by
3 posts views Thread by Master of C++ | last post: by
9 posts views Thread by C# Learner | last post: by
9 posts views Thread by Gustaf | last post: by
41 posts views Thread by Jordan | last post: by
7 posts views Thread by yogeshnelwadkar | last post: by
41 posts views Thread by Zytan | last post: by
1 post views Thread by George2 | last post: by
reply views Thread by leo001 | last post: by

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.