Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(most) bool return functions should instead throw on error #116

Open
timotheecour opened this issue Jun 14, 2017 · 0 comments
Open

(most) bool return functions should instead throw on error #116

timotheecour opened this issue Jun 14, 2017 · 0 comments

Comments

@timotheecour
Copy link
Collaborator

timotheecour commented Jun 14, 2017

this doesn't look very idiomatic, looks more like C-ism.

bool imwrite(in string path, size_t width, size_t height, ImageFormat format, BitDepth depth, ubyte[] data);

it's so easy to misuse and ignore return code, just like in C.
Why not throw on error, with an FileException error that has a path field?

If the bool return was the make the function nothrow, i don't think that's a good justification: in terms of performance, the cost of whatever imwrite is doing will dwarf exception handling anyways.
It's also more idiomatic, safe, can show more context, easier to use, etc.

EDIT:
also, it would make it more consistent with imread which throws ImageIOException and doesn't have C-like return error codes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants