__declspec(noreturn)
- From: Ulrich Eckhardt <eckhardt@xxxxxxxxxxxxxx>
- Date: Wed, 14 Sep 2005 09:10:11 +0200
Hi!
I have a utility function that composes an error message and throws a
std::runtime_error with it:
void throw_error( char const* str)
{
std::string msg;
msg += "my tool:";
msg += str;
throw std::runtime_error(msg);
}
So far, so good, but when I have a function that searches and returns
something:
foo const* search_foo()
{
...
// not found
throw_error("couldn't find foo");
}
The compiler complains that not all paths return something. Of course, I
could add a return 0 statement after the throw_error call, but my idea was
to tell the compiler that throw_error doesn't return by declaring it like
this:
void __declspec(noreturn) throw_error( char const* str);
Now, the compiler also doesn't complain, just as the docs[1] say. However, I
only found use of this function with things like exit(), _exit() and
abort(), which indeed do not return by terminating the program.
Now to my question: is this technique safe when the function throws an
exception? I could well imagine that cleanup code that would have to be
executed during stack unwinding is omitted for functions that have the
noreturn attribute - it is not explicitly documented if it works for
functions that always throw.
Can anybody shed some light on this?
Uli
[1] first hit for 'noreturn' on MSDN.
--
http://got.to/quote
Read this as I won't help you unless you make your posts readable or provide
a fascinating problem.
.
- Follow-Ups:
- Re: __declspec(noreturn)
- From: Jochen Kalmbach [MVP]
- Re: __declspec(noreturn)
- Prev by Date: Re: Charles Petzold ! How to start?
- Next by Date: Re: __declspec(noreturn)
- Previous by thread: ATL DLL SQL / Access
- Next by thread: Re: __declspec(noreturn)
- Index(es):
Relevant Pages
|