Topic: a exception re-throw question
Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1998/04/29 Raw View
In article F453439@ccnet.com, Gilbert Chang <gchang@ccnet.com> writes:
>Do the following two code segments have the same effects?
>
> try
> {
> .....
> }
> catch(SomeException & e)
> {
> throw e;
> }
>
> try
> {
> ....
> }
> catch(SomeException & e)
> {
> throw;
> }
This is more interesting than it looks at first. I think the question is
whether or not any stuff in a class derived from e gets sliced off by
"throw e". It obviously won't with "throw;", but it does with "throw
e;". This is because when an exception is explicitly thrown (as opposed
to rethrown), the object being thrown is copied. In the first case, it
is copied as the static type SomeException, even if the original
exception was some class derived from SomeException. If it's rethrown,
the copy doesn't take place, and the ultimate handler receives whatever
the original exception type was, even if it's something derived from
SomeException.
--
Ciao,
Paul
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@Eng (Steve Clamage)
Date: 1998/04/27 Raw View
In article F453439@ccnet.com, Gilbert Chang <gchang@ccnet.com> writes:
>Do the following two code segments have the same effects?
>
>code segment 1:
>try
>{
>.....
>}
>catch(SomeException & e)
>{
> throw e.foo();
>}
The throw-clause throws whatever is returned by e.foo, which
you don't specify here. If e.foo returns void, the throw-clause
is invalid.
>code segment 2:
>
>try
>{
>....
>}
>catch(SomeException & e)
>{
> e.foo();
> throw;
>}
The throw-clause throws e, the same exception that was passed in.
---
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Gilbert Chang <gchang@ccnet.com>
Date: 1998/04/27 Raw View
Do the following two code segments have the same effects?
code segment 1:
try
{
....
}
catch(SomeException & e)
{
throw e.foo();
}
code segment 2:
try
{
...
}
catch(SomeException & e)
{
e.foo();
throw;
}
Thanks
Gilbert Chang
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Gilbert Chang <gchang@ccnet.com>
Date: 1998/04/28 Raw View
Sorry for the incomplete and dumb question. Actually foo() is irrelevant.
What I really I wanted to ask was if "throw" and "throw e" have the same
effect. Thanks.
Steve Clamage wrote:
> In article F453439@ccnet.com, Gilbert Chang <gchang@ccnet.com> writes:
> >Do the following two code segments have the same effects?
> >
> >code segment 1:
> >try
> >{
> >.....
> >}
> >catch(SomeException & e)
> >{
> > throw e.foo();
> >}
>
> The throw-clause throws whatever is returned by e.foo, which
> you don't specify here. If e.foo returns void, the throw-clause
> is invalid.
>
> >code segment 2:
> >
> >try
> >{
> >....
> >}
> >catch(SomeException & e)
> >{
> > e.foo();
> > throw;
> >}
>
> The throw-clause throws e, the same exception that was passed in.
>
> ---
> Steve Clamage, stephen.clamage@sun.com
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]