Skip to content

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

@timotheecour

Description

@timotheecour

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions