kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Don't throw exception in non-exceptional circumstances
rodzic
7c378476e8
commit
66ba92cfb6
|
@ -172,6 +172,27 @@ SANE_Status wrap_exceptions_to_status_code(const char* func, F&& function)
|
|||
}
|
||||
}
|
||||
|
||||
template<class F>
|
||||
SANE_Status wrap_exceptions_to_status_code_return(const char* func, F&& function)
|
||||
{
|
||||
try {
|
||||
return function();
|
||||
} catch (const SaneException& exc) {
|
||||
DBG(DBG_error, "%s: got error: %s\n", func, exc.what());
|
||||
return exc.status();
|
||||
} catch (const std::bad_alloc& exc) {
|
||||
(void) exc;
|
||||
DBG(DBG_error, "%s: failed to allocate memory\n", func);
|
||||
return SANE_STATUS_NO_MEM;
|
||||
} catch (const std::exception& exc) {
|
||||
DBG(DBG_error, "%s: got uncaught exception: %s\n", func, exc.what());
|
||||
return SANE_STATUS_INVAL;
|
||||
} catch (...) {
|
||||
DBG(DBG_error, "%s: got unknown uncaught exception\n", func);
|
||||
return SANE_STATUS_INVAL;
|
||||
}
|
||||
}
|
||||
|
||||
template<class F>
|
||||
void catch_all_exceptions(const char* func, F&& function)
|
||||
{
|
||||
|
|
|
@ -6236,7 +6236,8 @@ SANE_Status sane_start(SANE_Handle handle)
|
|||
});
|
||||
}
|
||||
|
||||
void sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* len)
|
||||
// returns SANE_STATUS_GOOD if there are more data, SANE_STATUS_EOF otherwise
|
||||
SANE_Status sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* len)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
Genesys_Scanner* s = reinterpret_cast<Genesys_Scanner*>(handle);
|
||||
|
@ -6282,7 +6283,7 @@ void sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_
|
|||
dev->cmd_set->move_back_home(dev, false);
|
||||
dev->parking = true;
|
||||
}
|
||||
throw SaneException(SANE_STATUS_EOF);
|
||||
return SANE_STATUS_EOF;
|
||||
}
|
||||
|
||||
local_len = max_len;
|
||||
|
@ -6294,14 +6295,15 @@ void sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_
|
|||
dbg.log(DBG_error, "error: returning incorrect length");
|
||||
}
|
||||
DBG(DBG_proc, "%s: %d bytes returned\n", __func__, *len);
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
SANE_GENESYS_API_LINKAGE
|
||||
SANE_Status sane_read(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* len)
|
||||
{
|
||||
return wrap_exceptions_to_status_code(__func__, [=]()
|
||||
return wrap_exceptions_to_status_code_return(__func__, [=]()
|
||||
{
|
||||
sane_read_impl(handle, buf, max_len, len);
|
||||
return sane_read_impl(handle, buf, max_len, len);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue