Stop throwing in destructors
When exception processing is unwinding the stack, any exception thrown in destructors end up std::terminate()-in our process. Since all workarounds to report errors from destructors seems an overkill, and the only important place where we should notify the user about a failure is the stdex::stream::cache::~cache() (data loss occurs when failure happens here), and if we'd throw in stdex::stream::cache:: ~cache(), our process would get terminated anyway so the data loss is inevitable, let's just silence this for now and come up with a better solution later if we get smarter anytime in the future. Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
69f2c639cd
commit
bfd8aaff65
@ -86,7 +86,7 @@ namespace stdex
|
|||||||
public:
|
public:
|
||||||
basic(_In_ state_t state = state_t::ok) : m_state(state) {}
|
basic(_In_ state_t state = state_t::ok) : m_state(state) {}
|
||||||
|
|
||||||
virtual ~basic() noexcept(false) {}
|
virtual ~basic() {}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Reads block of data from the stream
|
/// Reads block of data from the stream
|
||||||
@ -1852,9 +1852,10 @@ namespace stdex
|
|||||||
#endif
|
#endif
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual ~cache() noexcept(false)
|
virtual ~cache()
|
||||||
{
|
{
|
||||||
if (m_source) {
|
if (m_source) {
|
||||||
|
try {
|
||||||
flush_cache();
|
flush_cache();
|
||||||
if (!ok()) _Unlikely_
|
if (!ok()) _Unlikely_
|
||||||
throw std::system_error(sys_error(), std::system_category(), "failed to flush cache"); // Data loss occurred
|
throw std::system_error(sys_error(), std::system_category(), "failed to flush cache"); // Data loss occurred
|
||||||
@ -1864,6 +1865,8 @@ namespace stdex
|
|||||||
m_source->set_mtime(m_mtime);
|
m_source->set_mtime(m_mtime);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
catch (...) {} // TODO: Never throw in destructors. If we'd throw here exception stack unwinding would std::terminate() our process anyway. Is there a way to catch this?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual _Success_(return != 0 || length == 0) size_t read(
|
virtual _Success_(return != 0 || length == 0) size_t read(
|
||||||
|
@ -171,10 +171,12 @@ namespace stdex
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~basic_sys_object() noexcept(false)
|
virtual ~basic_sys_object()
|
||||||
{
|
{
|
||||||
if (m_h != TR::invalid_handle)
|
if (m_h != TR::invalid_handle) {
|
||||||
TR::close(m_h);
|
try { TR::close(m_h); }
|
||||||
|
catch (...) {} // Failure to close a handle should not be that devastating as throwing in a destructor may be.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -61,6 +61,7 @@ namespace stdex
|
|||||||
|
|
||||||
virtual ~zlib_writer()
|
virtual ~zlib_writer()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
m_zlib.avail_in = 0;
|
m_zlib.avail_in = 0;
|
||||||
m_zlib.next_in = NULL;
|
m_zlib.next_in = NULL;
|
||||||
do {
|
do {
|
||||||
@ -76,6 +77,8 @@ namespace stdex
|
|||||||
// deflateReset(&m_zlib);
|
// deflateReset(&m_zlib);
|
||||||
deflateEnd(&m_zlib);
|
deflateEnd(&m_zlib);
|
||||||
}
|
}
|
||||||
|
catch (...) {} // TODO: Never throw in destructors. If we'd throw here exception stack unwinding would std::terminate() our process anyway. Is there a way to catch this?
|
||||||
|
}
|
||||||
|
|
||||||
virtual _Success_(return != 0) size_t write(
|
virtual _Success_(return != 0) size_t write(
|
||||||
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
|
_In_reads_bytes_opt_(length) const void* data, _In_ size_t length)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user