scifir / scifir-units

A C++ library of science for creating scalar, vectorial and field units, angles, coordinates and points, lab numbers, special units like pH, zone ids, astro ids, matrices of units, among other features! (under development)
GNU General Public License v3.0
2 stars 1 forks source link

No cohesive error handling #2

Open cdfrey opened 1 year ago

cdfrey commented 1 year ago

After reading through the code at:

https://github.com/scifir/scifir-units/blob/master/units/scalar_unit.cpp

I noticed that there was no cohesive error handling. Perhaps that is a later part of your roadmap? Figured I would mention it anyway, since there is no way to programmatically determine if an operation failed, nor recover if it did. Only messages sent to stderr.

iarfen commented 1 month ago

What would you use for cohesive error handling?

cdfrey commented 1 month ago

@iarfen Hi there!

It's been over a year since I left this, so I had to scan over the code again to try to remember. But I believe I was looking at the operator overloads.

Look at the if statements checking "has_dimentions()" for example. The error case is handled by a call to cerr. The logging is great, but there is no programmatic way to handle the problem. The code continues to run without any further checks or exceptions.

If I call the operator+=() for example, there is a chance that my object will not be modified at all, and I won't know unless I compare it with a copy of itself before the call.

I would suggest that any case that an operation cannot complete, where cerr is called, that an exception also be thrown. If exceptions are not part of the design of this library, then set a flag in the object, so a call to .error() or something can be checked after a number of complex calculations, to know whether it succeeded or not.

Just my $0.02.