celtera / libremidi

A modern C++ MIDI 1 / MIDI 2 real-time & file I/O library. Supports Windows, macOS, Linux and WebMIDI.
Other
456 stars 51 forks source link

feature/error_code for error handling #100

Closed jcelerier closed 8 months ago

jcelerier commented 8 months ago

Title says it all, the exception-based error handling is terrible.

jcelerier commented 8 months ago

having some good progress here with std::error_code which looks like the error reporting system that fits this library best : feature/error_code

Many functions that did fail silently now report errors back to the caller.

jcelerier commented 8 months ago

however there is an API break: https://en.cppreference.com/w/cpp/error/error_code/operator_bool

before, if(midi.open_port()) would return true if the port could be opened. But std::error_code uses true-y values to indicate that an error happened : the conditions have to be changed into if(midi.open_port() != std::error_code{})

jcelerier commented 8 months ago

also investigating https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1028r6.pdf through https://github.com/ned14/status-code ; it is a clear improvement

jcelerier commented 8 months ago

done in master - right now it uses stdx::error until we get C++26 and std::error