paupino / rust-decimal

Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations.
https://docs.rs/rust_decimal/
MIT License
1.02k stars 183 forks source link

Review error handling within Decimal #49

Open paupino opened 7 years ago

paupino commented 7 years ago

There are some areas where panic is warranted however there are others (e.g. rescale, from_bytes_le) that we could utilize Rust's error handling further. In addition, with libraries such as error-chain we can perhaps make the error handling experience richer with little overhead.

jekirl commented 7 years ago

I would propose that panics be only for truly unrecoverable errors, which in this case should be limited to debug mode perhaps? In general I think there should be no panics for the Mul/Add/Div/Sub/etc traits, and instead there be a checked_mul/div/add/sub/etc function for each implemented under the Decimal trait that returns an error type (through error-chain). Perhaps having panic on release and/or debug can be a feature flag?

paupino commented 6 years ago

Have expanded checked operators into #80. I do like the idea of debug mode only panic's however would like to perhaps come up with a clear set of rules. For div, for example, I'm thinking:

Thoughts?