Samuel-Tyler / fast_ber

A C++11 ASN.1 BER Encoding and Decoding Library
Boost Software License 1.0
84 stars 11 forks source link

Constructors should throw on fail #21

Open Samuel-Tyler opened 4 years ago

Samuel-Tyler commented 4 years ago

Currently fast_ber does not throw exceptions. Most functions are labelled noexcept.

However, the only way for constructors to report errors is to throw an exception. Utility should be added such that constructors which may fail throw an error.

Default constructors should not throw.

Any existing functionality that returns an error code should not be affected.

melg8 commented 4 years ago

I really like your "No exceptions, no RTTI" style approach, so can this be done in some way, so you can disable "throw something;" code on platforms, where exceptions are disabled?

Samuel-Tyler commented 4 years ago

Sure, I can create a macro such that these failures will abort rather than throw.

In every case where exceptions are needed to report errors (such as constructors and operator=) there will be an alternative method (assign) which will return an error code.

Finally, most functions are currently labelled no except. Functions without this label should be avoided in code with exceptions disabled.