473,765 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

throwing dtors...

Is it every appropriate to throw in a dtor? I am thinking about a simple
example of a wrapper around a POSIX file...
_______________ _______________ _______________ _______________ ____________
class file {
FILE* m_handle;

public:
// [...];

~file() /* throw() */ {
int const status fclose(m_handle );
if (status) {
/* shi% hit the fan:
http://www.opengroup.org/onlinepubs/...sh/fclose.html
/*

// [what now?]
}
}
};
_______________ _______________ _______________ _______________ ____________
How to properly handle `EAGAIN' in dtor? Well, what about any error for that
matter? I am a C programmer and only code C++ for fun, and some in-house
projects. If I were really going to create C++ application and release it
into the wild, well, how would you advise me to handle the case above? I am
interested in how throwing in a dtor effects dynamic destruction... Would
something like the following be legal?

<pseudo code!!!!>
_______________ _______________ _______________ _______________ ___
struct throw_from_dtor {
int const m_status;

public:
throw_from_dtor (int const status)
m_status(status ) {}

int get_status() const { return m_status; }
};

class file {
FILE* m_handle;

public:
// [ctor];

~file() {
int const status = fclose(m_handle );
if (status) {
throw throw_from_dtor (status);
}
}
};
int main() {
file* f = new file();
try {
delete f;
} catch(throw_fro m_dtor const& e) {
// handle error from `e.get_status() '
delete f;
}
return 0;
}
_______________ _______________ _______________ _______________ ___
?
or what about using smart pointer...

int main() {
std::auto_ptr<f ilef;
try {
f.reset(new file());
} catch(throw_fro m_dtor const& e) {
// handle error from `e.get_status() '
}
}

?


Please keep in mind that refusing to not handle an error from `fclose' could
resule is HORRIBLE things down the road... Think massive data lost...
Perhaps __permanent__ data-! OUCH!!!

;^/

Oct 2 '08
21 1720
On Oct 2, 7:47 am, anon <a...@no.invali dwrote:

[...]
What can you do when fclose fails?
At the very least, you must notify the user. Generally, you'll
want to delete the file, and usually return an error code to the
OS.

About the only exception I can think of is a log file. If
closing that fails, you probably want to continue anyway,
ignoring the error. (Theoretically, you should log the
error:-).)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 2 '08 #11
On Oct 2, 9:20 am, "Chris M. Thomasson" <n...@spam.inva lidwrote:
"Paavo Helde" <nob...@ebi.eew rote in message
[...]
For most applications I believe a proper behavior would be
to try to log the error somewhere, then either continue or
abort, depending on the application type.
What if the application needs to copy a file to disk and
destroy the original? If `fclose()' fails on the destination
file, well, the application won't know about it and will
continue on and destroy the source file. Well, the
destination file is by definition in a non-coherent state
because `fclose()' failed to "do its thing". Well, the lost
data is gone forever. A log file will only show why the data
was lost, it does not prevent it. In this case I bet the user
wished the application just terminated when the `fclose()'
failed. Or better, I bet the user would like to be able to
catch and explicitly handle this case...
This is why it is important in such cases to return an error
status (EXIT_FAILURE) from main. A typical idiom in Unix would
be something like:

program filename tempFile && mv tempFile filename

And all too often, the program won't flush standard out and
verify that the flush worked. (All to many programs totally
ignore the fact that output might fail.) With the result that
if you fill up the disk, you loose important data.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 2 '08 #12
"Chris M. Thomasson" <no@spam.invali dkirjutas:
>
"Paavo Helde" <no****@ebi.eew rote in message
news:Xn******** *************** **@216.196.97.1 31...
>"Chris M. Thomasson" <no@spam.invali dkirjutas:
>>Is it every appropriate to throw in a dtor? I am thinking about a
simple example of a wrapper around a POSIX file...
_____________ _______________ _______________ _______________ ___________
__
[...]
>>
Throwing from a dtor is not really advisable in C++. It can easily
lead to duplicate throws during stack unwinding, and calling
terminate() as the result.

The C++ RAII model is built up on the assumption that releasing the
resource always succeeds (or its failure can be ignored by upper
levels). If this is not the case, then the application logic becomes
very complex immediately, essentially you are back in C again.

In any case, I would suggest to move any activity which can fail out
of the destructor, into a separate member function which has to be
called explicitly before destroying of the object, possibly from
inside a try- catch block dealing with errors.

I think I agree here. Since, IMVHO, at least attempting to gracefully
handle `fclose()', such as deferred retrying in the case of `EINTR' or
`EAGAIN', is extremely important. Therefore, it sure seems to make
sense to force the used to explicitly call a member function which
invokes `fclose()' and throws when a very bad error its encountered
(e.g., something other than EINTR or EAGAIN).
Exceptions are for communicating situations which cannot be dealt locally
to the upper levels in the application logic. If the error can be dealt
locally, there is no need for an exception.

I am not familiar with EAGAIN, but can't this be handled locally as well?
[...]
What if the application needs to copy a file to disk and destroy the
original? If `fclose()' fails on the destination file, well, the
application won't know about it and will continue on and destroy the
Apparently, it has to know about this in this case. So fclose() result
has to be somehow communicated to the calling application. Unfortunately
it cannot be done just by throwing an exception from the destructor.
Well, in principle there is the uncaught_except ion() function which one
could check in the dtor and decide whether to throw a new exception or if
there is one already in the progress, and so no new exception is needed.
However, there were some gotchas which made uncaught_except ion() mostly
useless IIRC.

Paavo

Oct 2 '08 #13
In article <X5************ ******@newsfe02 .iad>,
Chris M. Thomasson <no@spam.invali dwrote:
>"anon" <an**@no.invali dwrote in message
news:gc******* ***@news01.vers atel.de...
>Chris M. Thomasson wrote:
>>Is it every appropriate to throw in a dtor? I am thinking about a simple
example of a wrapper around a POSIX file...

Take a look here:
http://www.parashift.com/c++-faq-lit...html#faq-11.13

Okay; I will give it a look.

[...]
>How would you handle it in C?
[...]
>What can you do when fclose fails?

Well, it depends on the error:

http://www.opengroup.org/onlinepubs/...sh/fclose.html

For instance, fclose can get interrupted by a signal. In this case, you need
to reissue the operation; e.g:
______________ _______________ _______________ _______________ ___
struct file {
FILE* handle;
};

int file_close(
struct file* const this
) {
int status;
do {
status = fclose(this->handle);
} while (status == EOF && errno == EINTR);
return status;
}
That's precisely your answer:

Do exactly what you would do in C in your file_close method
and call it from your destructor:

File::~File()
{
if(0 != file_close()) {
// log the error
// or std::terminate?
}
}

int File::file_clos e()
{
int status = 0;
do {
status = fclose(handle);
} while (status == EOF && errno == EINTR);
return status;
}

>Or, what if it returns `EAGAIN', well, this certainly needs to be handled.
So handle EAGAIN. 2 ways:

1- in file_close()
2- if impossible in file_close() then you must require that the client do
it by explicitely calling file_close() and dealing with errors.

>Fine... Now, a user needs to copy a file to a disk, and destroy the
original. Okay. It creates two file objects (e.g., src and dest:)

{
file src(...);
file dest(...);

// Then it performs the copy operation:

[copy src to dest]
}

Now the code-block goes out of scope, and no exceptions were thrown during
the copy process, HOWEVER, the call to `fclose()' in the dest object
failed!!!! Well, the user thinks everything is fine because the completely
retarded ignorant moron file object did not report the fuc%ing error! So the
user operates in ignorance and happily destroys the original file thinking
that the file was COMPLETELY copied onto the disk! WRONG! The file was
partially copied because `fclose()' failed to do its thing and properly
flush the buffers, or whatever... Now, the missing file data is LOST
__forever__! OUCH!!!
That's a failure of the application

foo()
{
file src(...)
file dest(...)
dest.copy(src);

// Must ensure that dest was correctly flushed/sync/close *before*
// deleting src
if(0 == dest.file_close ())
{
src.delete();
} else {
// whatever is needed to recover
}
}
Oct 2 '08 #14
"Chris M. Thomasson" <no@spam.invali dwrote in message
news:k4******** **********@news fe06.iad...
Is it every appropriate to throw in a dtor? I am thinking about a simple
example of a wrapper around a POSIX file...
[...]

Thank you all (e.g., anon, James Kanze and Paavo Helde) for your excellent
insight. After absorbing your input, I think the way to go would be
something like; thread-safety wrt the `file::m_handle ' member aside for a
moment:
_______________ _______________ _______________ _______________ _____
#if ! defined(FILE_DT OR_UNEXPECTED)
# define FILE_DTOR_UNEXP ECTED(mp_file) assert(false)
#endif
class file {
FILE* m_handle;
public:
struct error {
struct base {
int const m_status;
base(int const status) : m_status(status ) {}
};

struct bad_descriptor : public base {
bad_descriptor( ) : base(EBADF) {}
};

struct exceeds_offset : public base {
exceeds_offset( ) : base(EFBIG) {}
};

struct process_orphane d : public base {
process_orphane d() : base(EIO) {}
};

struct no_free_space : public base {
no_free_space() : base(ENOSPC) {}
};

struct pipe_not_for_re ading : public base {
pipe_not_for_re ading() : base(EPIPE) {}
};

struct non_existing_de vice : public base {
non_existing_de vice() : base(ENXIO) {}
};

struct already_closed : public base {
already_closed( ) : base(0) {}
};

struct unknown : public base {
unknown() : base(0) {}
};

static void throw_status(in t const status) {
assert(! status);
switch (status) {
case EBADF:
throw bad_descriptor( );
case EFBIG:
throw exceeds_offset( );
case EIO:
throw process_orphane d();
case ENOSPC:
throw no_free_space() ;
case EPIPE:
throw pipe_not_for_re ading();
case ENXIO:
throw non_existing_de vice();
default:
throw unknown();
}
}
};
private:
int prv_close() throw() {
int status;
do {
status = std::fclose(m_h andle);
} while (status == EOF && errno == EINTR);
return status;
}
public:
bool close(bool handle_eagain = true, unsigned backoff = 1) {
if (! m_handle) {
throw error::already_ closed();
}
retry:
int status = prv_close();
if (status == EOF) {
if (errno != EAGAIN) {
error::throw_st atus(errno);
} else if (handle_eagain) {
sleep(backoff);
goto retry;
}
return false;
}
m_handle = NULL;
return true;
}
file(/* [...] */) : m_handle(NULL) {
// [...];
}

// [...];

~file() throw() {
if (m_handle) {
if (prv_close() == EOF) {
FILE_DTOR_UNEXP ECTED(m_handle) ;
}
}
}
};
_______________ _______________ _______________ _______________ _____

And explicitly document that `file::close()' returns true if everything
worked, false if the file was non-blocking and the operation would have
blocked, or throws if shi% hit the fan. Then note that `file::close()' only
returns false when the `file::close(ha ndle_eagain)' parameter is false.
Although James Kanze seems to suggest that `file::close()' should return a
error code; perhaps the value from errno. However, this approach requires
the user to decipher the errno value and act accordingly. Where the
fine-grain exception thing my example code uses decodes errno into specific
exception types that the user can catch. AFAICT, I think the fine-grain
exceptions are more C++'ish than return specific error codes. The fact that
`file::close()' returns a simple bool when a `EAGAIN' is encountered should
be okay.
Now an application could do something like; taking my file-copy example:
_______________ _______________ _______________ _______________ _____
void foo() {
try {
file src(...);
file dest(...);
dest.copy(src);
src.close();
dest.close();
src.delete();
} catch (file::error::b ad_descriptor const& e) {
// [...];
} catch (file::error::e xceeds_offset const& e) {
// [...];
} catch (file::error::p rocess_orphaned const& e) {
// [...];
} catch (file::error::n o_free_space const& e) {
// [...];
} catch (file::error::p ipe_not_for_rea ding const& e) {
// [...];
} catch (file::error::n on_existing_dev ice const& e) {
// [...];
} catch (file::error::a lready_closed const& e) {
// [...];
} catch (file::error::u nknown const& e) {
// [...];
}
}
_______________ _______________ _______________ _______________ _____

or if the application does not care which "specific" error caused things to
go bad it could do:
_______________ _______________ _______________ _______________ _____
void foo() {
try {
file src(...);
file dest(...);
dest.copy(src);
src.close();
dest.close();
src.delete();
} catch (file::error::b ase& e) {
// [...];
}
}
_______________ _______________ _______________ _______________ _____

Does that look Kosher to you C++ gurus?
;^)

Oct 2 '08 #15
On Oct 2, 2:35 pm, "Chris M. Thomasson" <n...@spam.inva lidwrote:
"Chris M. Thomasson" <n...@spam.inva lidwrote in
messagenews:k4* *************** **@newsfe06.iad ...Is it every
appropriate to throw in a dtor? I am thinking about a simple
example of a wrapper around a POSIX file...
[...]
Although James Kanze seems to suggest that `file::close()'
should return a error code; perhaps the value from errno.
I said "error code" because the expression "return a return
code" sounded funny. It should return as much information as is
necessary, but not necessarily any more. Typically, it will
return a class local enum. Depending on the intended audience,
this can be as simple as:

enum ErrorCode
{
succeeded,
failed
} ;

Alternatively, you can categorize the errors in a somewhat finer
way.

In some cases, I also provide a means of accessing a system
dependent error code, in addition to the above. In such cases,
I'll also typically provide a way of mapping that error code to
a message.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 2 '08 #16
"James Kanze" <ja*********@gm ail.comwrote in message
news:c9******** *************** ***********@r66 g2000hsg.google groups.com...
On Oct 2, 2:35 pm, "Chris M. Thomasson" <n...@spam.inva lidwrote:
"Chris M. Thomasson" <n...@spam.inva lidwrote in
messagenews:k4* *************** **@newsfe06.iad ...Is it every
appropriate to throw in a dtor? I am thinking about a simple
example of a wrapper around a POSIX file...
[...]
Although James Kanze seems to suggest that `file::close()'
should return a error code; perhaps the value from errno.
I said "error code" because the expression "return a return
code" sounded funny. It should return as much information as is
necessary, but not necessarily any more. Typically, it will
return a class local enum. Depending on the intended audience,
this can be as simple as:
enum ErrorCode
{
succeeded,
failed
} ;
Alternatively, you can categorize the errors in a somewhat finer
way.
Humm, perhaps something like:

class file {
public:
struct error_code {
enum value {
succeeded = 0x0,
failed = 0x1,
bad_descriptor = failed | 0x2,
exceeds_offset = failed | 0x4,
process_orphane d = failed | 0x8,
no_free_space = failed | 0x10,
pipe_not_for_re ading = failed | 0x20,
non_existing_de vice = failed | 0x40,
already_closed = failed | 0x80,
unknown = failed | 0x100
};
};
};
That way you can combine several error codes in a single value; sometimes
that ability might be fairly "useful" and/or convenient. However, IMVHO, how
does this improve on my example with fine-grain exceptions? Do C++
programmers tolerate having to examine return values for error-codes? I
think some of them would be fine with a simple boolean in certain cases, but
more than that would perhaps sound too C`ish?

In some cases, I also provide a means of accessing a system
dependent error code, in addition to the above. In such cases,
I'll also typically provide a way of mapping that error code to
a message.
Yeah; that's definitely convenient!

Oct 2 '08 #17
"Chris M. Thomasson" <no@spam.invali dwrote in
news:X5******** **********@news fe02.iad:
"anon" <an**@no.invali dwrote in message
news:gc******** **@news01.versa tel.de...
>Chris M. Thomasson wrote:
>>Is it every appropriate to throw in a dtor? I am thinking about a
simple example of a wrapper around a POSIX file...

Take a look here:
http://www.parashift.com/c++-faq-lit...html#faq-11.13

Okay; I will give it a look.

[...]
>How would you handle it in C?
[...]
>What can you do when fclose fails?

Well, it depends on the error:

http://www.opengroup.org/onlinepubs/...sh/fclose.html

For instance, fclose can get interrupted by a signal. In this case,
you need to reissue the operation; e.g:
_______________ _______________ _______________ _______________ __
struct file {
FILE* handle;
};

int file_close(
struct file* const this
) {
int status;
do {
status = fclose(this->handle);
} while (status == EOF && errno == EINTR);
return status;
}
_______________ _______________ _______________ _______________ __


Or, what if it returns `EAGAIN', well, this certainly needs to be
handled. However, it would be better to let the application to handle
this, not do it implicitly within the `file_close()' function. There
are many ways to handle this. That's not the problem. The problem is
when a retarded program does not handle it! IHO, any program that does
not explicitly handle errors from `fclose()' is severely broken and
VERY dangerous. Let me give you a example... Imagine a C++ wrapper
around a C FILE... Fine. Imagine the dtor looks like this:

class file {
FILE* m_handle;

public:
~file() throw() {
fclose(m_handle );
}
};

Fine... Now, a user needs to copy a file to a disk, and destroy the
original. Okay. It creates two file objects (e.g., src and dest:)

{
file src(...);
file dest(...);

// Then it performs the copy operation:

[copy src to dest]
}

Now the code-block goes out of scope, and no exceptions were thrown
during the copy process, HOWEVER, the call to `fclose()' in the dest
object failed!!!! Well, the user thinks everything is fine because the
completely retarded ignorant moron file object did not report the
fuc%ing error! So the user operates in ignorance and happily destroys
the original file thinking that the file was COMPLETELY copied onto
the disk! WRONG! The file was partially copied because `fclose()'
failed to do its thing and properly flush the buffers, or whatever...
Now, the missing file data is LOST __forever__! OUCH!!!
This is why its ESSENTIAL to report and handle errors from
`fclose()'... If `fclose()' fails, you can't be so sure that the file
is 100% coherent...
Any thoughts?
Yep, you're not using exceptions appropriately. What should be
happening is your loop around fclose should be in the destructor itself.
By throwing an exception out of the destructor you are effectively
saying that the object was unable to be destroyed. Now you're in for a
whole world of hurt. How can you possibly recover from that? The
object is already on its way out of scope, and now you can't destroy it.
You can't abort the object going out of scope. Really, if the caller
really was ready to handle errors from fclose, then they should be using
whatever method of the file class that just does fclose before allowing
the object to fall out of scope.

Additionally a whole different world of hurt happens is you have an
array of these things. Let's assume an array of 10 of them. Also let's
assume that object #7 throws an exception during construction. So the
program dutifully destroys all of the previous objects that it had
previously fully constructed. And object #3 throws an exception during
its destructor. Now you have 2 active exceptions running around.
That's a short trip to a terminated program. You can't catch it. This
is probably the best example of why allowing exceptions to propogate out
of destructors is a Bad Thing.
Oct 2 '08 #18
In article <gq************ *******@newsfe0 3.iad>,
Chris M. Thomasson <no@spam.invali dwrote:
>
Humm, perhaps something like:

class file {
public:
struct error_code {
enum value {
succeeded = 0x0,
failed = 0x1,
OK
bad_descriptor = failed | 0x2,
exceeds_offset = failed | 0x4,
process_orphane d = failed | 0x8,
no_free_space = failed | 0x10,
pipe_not_for_re ading = failed | 0x20,
non_existing_de vice = failed | 0x40,
All fatal failures.
already_closed = failed | 0x80,
Is this really a failure? The file is correctly
closed.
unknown = failed | 0x100
Still a fatal failure.
>
That way you can combine several error codes in a single value; sometimes
that ability might be fairly "useful" and/or convenient. However, IMVHO, how
does this improve on my example with fine-grain exceptions? Do C++
programmers tolerate having to examine return values for error-codes? I
think some of them would be fine with a simple boolean in certain cases, but
more than that would perhaps sound too C`ish?
Hmm, complexity, complexity. Is that complexity necessary? Good C++
programmers like all other good programmer tolerate complexity when
complexity is needed. However, typically, the good C++ programmer is
trained in the concept of implementation hiding where unecessary
complexity is hidden away from the client code under a simpler to use
interface. If the complexity is needed for the client then the
complexity must be exposed. However, if it is not needed, it should
not be exposed.

Large application programming is in large part an exercise in
complexity management. If you try to build a house with grains of
sands, you are up against it. Bricks are much much productive.

So back in the real world :-)
Typically, one file close failure, three things can be done:
1- Try again
2- Give up and continue anyway
3- Kill the application

In very rare case, it might be possible to delete some files to free
disk space but this is rarely a possible action.

In all these cases, logging is likely to be desirable.

1- Try again can quite possibly be encapsulated in a more advanced
close function if the client doesn't have real time requirements. So
this complexity often needs not be exposed to the client.

2 or 3 are likely to be the higher level logic reaction for an
irrecoverable error regardless of the cause fo the error. If you try
to copy a file, it is irrelevant if it failed due to out of disk space
or non-existing device. It failed. In a server, you might raise an
alarm and keep going in the hope that maybe next time it will work
(maybe logrotate will have run by then or the remote device will be
back online), in another case you just exit, most probably regardless
of the cause.

The logging of the cause of the error can very easily be encapsulate
(or if exceptions are used, what() can give you a useful string).

So in my opinion, in a large number of cases where multiples unique
error codes are used, a simpler interface:

bool DoItAndTryToRec overIfPossibleE lseLogAndReturn Failure()

is sufficient. Now in your particular case, it might not be
sufficient but make sure that the complexity is really needed because
if the client code has to deal with a more complex interface, it is
more likely to have bug and will take longer to develop.

Yannick
Oct 2 '08 #19
"Andre Kostur" <an***@kostur.n etwrote in message
news:Xn******** *************** ********@209.13 5.99.21...
"Chris M. Thomasson" <no@spam.invali dwrote in
news:X5******** **********@news fe02.iad:
>"anon" <an**@no.invali dwrote in message
news:gc******* ***@news01.vers atel.de...
>>Chris M. Thomasson wrote:
Is it every appropriate to throw in a dtor? I am thinking about a
simple example of a wrapper around a POSIX file...
[...]
>Any thoughts?

Yep, you're not using exceptions appropriately. What should be
happening is your loop around fclose should be in the destructor itself.
Right. I would only loop on `EINTR' in dtor, and perhaps have a bounded loop
on `EAGAIN' with a slight delay in between (e.g., sched_yield() or
something). I just would clearly document that if the user does not
explicitly close the file by invoking `file::close()' member-function then
the dtor will attempt to close, but if it fails, then no error condition
will be reported to the user at the time of dtor call.

By throwing an exception out of the destructor you are effectively
saying that the object was unable to be destroyed. Now you're in for a
whole world of hurt. How can you possibly recover from that? The
object is already on its way out of scope, and now you can't destroy it.
You can't abort the object going out of scope. Really, if the caller
really was ready to handle errors from fclose, then they should be using
whatever method of the file class that just does fclose before allowing
the object to fall out of scope.

Additionally a whole different world of hurt happens is you have an
array of these things. Let's assume an array of 10 of them. Also let's
assume that object #7 throws an exception during construction. So the
program dutifully destroys all of the previous objects that it had
previously fully constructed. And object #3 throws an exception during
its destructor. Now you have 2 active exceptions running around.
That's a short trip to a terminated program. You can't catch it. This
is probably the best example of why allowing exceptions to propogate out
of destructors is a Bad Thing.
I have concluded that something like the following would work:

http://groups.google.com/group/comp....0f3efc3e5ee5ed

The `file::~file()' is decorated with throw(), and does not throw anything.
If the user wants to be 100% sure that `fclose()' succeeds, then she/he
needs to call `file::close()' before the object gets destroyed. Now, this
member-function can throw from a fine-grain exception hierarchy if
`fclose()' bites the dust, and the user can catch specific error conditions
and act accordingly. This seems workable to me... What do you think?

Oct 2 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2871
by: Gerhard Wolfstieg | last post by:
The following situation: class A0 { static A0 *a0; // something like this to publish the pointer public: A0() { a0 = this; } virtual ~A0(){}
2
1515
by: SK | last post by:
What is the purpose of throwing exceptions in catch block. Bcos the exception is already thrown only, it is coming to the catch block.What is the purpose of throwing it again then!!!.....Help
5
4682
by: Mark Oueis | last post by:
I've been struggling with this question for a while. What is better design? To design functions to return error codes when an error occures, or to have them throw exceptions. If you chose the former, i have a few questions that need to be answered. 1) What about functions that need to return a value regardless of the error. How can they also return an error code unless the function has "output" parameters. This seems messy and...
6
2248
by: BigMan | last post by:
Is it safe to call nonvirtual member functions from ctors and dtors? What about virtual ones?
21
4440
by: mihai | last post by:
People say that is a bad technique to throw exception from constructors; and that the solution would be to create a function _create_ to initialize an object. What about copy constructors? How can we avoid throwing exceptions? If we already have an abject witch was initialized wit _create_ we will be forced to call create in copy constructor and to throw exceptions from it. Have a nice day,
1
1670
by: Farooq Khan | last post by:
i'm writing a class library having following code snippet. i want this class to report an error (by throwing an Exception) to the application using this class library. the problem is that within that try block there are several exceptions that this class itself needs to handle (interrnally). now when the exception, UserAlreadyRegistered, is thrown the class' catch block (within library) catches it and no exception is thrown to the...
40
13530
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.