Handling Exception

W

wongjoekmeu

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::eek:utofbound)
{
----
}
----------------------------------
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
 
T

TJ

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::eek:utofbound)
{
----
}
----------------------------------
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,133
Latest member
MDACVReview
Top