| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
02 Feb 2005 03:26:06 PM |
| Object: |
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
.
|
|
| User: "TJ" |
|
| Title: Re: Handling Exception |
03 Feb 2005 02:46:03 AM |
|
|
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
.
|
|
|
|

|
Related Articles |
|
|