dcv icon indicating copy to clipboard operation
dcv copied to clipboard

(most) bool return functions should instead throw on error

Open timotheecour opened this issue 8 years ago • 0 comments

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

timotheecour avatar Jun 14 '17 06:06 timotheecour