By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

Handling Exception

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.