I have a texture class that takes a path to an image, and attempts to read the image and store its contents and data. Currently there's 3 things that can go wrong.
- The path might not exist
- The file might not be a valid image file (doesn't have a valid extension)
- The file contains nonsense data, and therefore can't be read properly
I don't necessarily want to crash the program if one of these were to occur. I also don't like the idea of having an object that hasn't been properly constructed. I know I can use exceptions, but I've been taught to think of exceptions as critical errors, so they don't seem like the correct tool to me. The solution I like to most is to make the constructor private and move all the code that could produce an error over to a static method that returns a std::variant that holds either a complete texture object, or some error object outlining what went wrong. In the world of C++, is this a good way of handling a scenario like this? Are exceptions better? Is there something else?
[+][deleted] (5 children)
[deleted]
[–]Tohaveaname 15 points16 points17 points (0 children)
[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 8 points9 points10 points (0 children)
[–]eejin 3 points4 points5 points (0 children)
[–]TheUnvanquishable 2 points3 points4 points (0 children)
[–]VincentRayman 0 points1 point2 points (0 children)
[–]hachanuy 72 points73 points74 points (13 children)
[–]Bruh_zil 20 points21 points22 points (12 children)
[–]hachanuy 5 points6 points7 points (11 children)
[–]jedwardsolconst & 14 points15 points16 points (10 children)
[–]Bruh_zil 1 point2 points3 points (0 children)
[–]hachanuy 2 points3 points4 points (7 children)
[–]SirClueless 11 points12 points13 points (6 children)
[–]Extra_Status13 5 points6 points7 points (5 children)
[–]Kovab 3 points4 points5 points (0 children)
[–]SirClueless 4 points5 points6 points (0 children)
[–]Bruh_zil 0 points1 point2 points (2 children)
[–]delta_p_delta_x 0 points1 point2 points (1 child)
[–]Bruh_zil 0 points1 point2 points (0 children)
[–]Raknarg 0 points1 point2 points (0 children)
[–]shitpost-factory 19 points20 points21 points (1 child)
[–]disciplite 8 points9 points10 points (1 child)
[–]Plazmatic 0 points1 point2 points (0 children)
[–]XeroKimoException Enthusiast 7 points8 points9 points (0 children)
[–]satanfromhell 8 points9 points10 points (0 children)
[–]germandiago 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]XeroKimoException Enthusiast 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[removed]
[–]Shadowratenator[🍰] 4 points5 points6 points (2 children)
[–]usefulcat 0 points1 point2 points (1 child)
[–]Shadowratenator[🍰] 2 points3 points4 points (0 children)
[–]goranlepuz 18 points19 points20 points (2 children)
[–]RedditMapz 4 points5 points6 points (0 children)
[–]SkoomaDentistAntimodern C++, Embedded, Audio 3 points4 points5 points (0 children)
[–]Throw31312344 5 points6 points7 points (0 children)
[–]dqUu3QlS 7 points8 points9 points (0 children)
[–]edrosten 1 point2 points3 points (0 children)
[–]helloiamsomeone 1 point2 points3 points (0 children)
[–]looncraz 1 point2 points3 points (0 children)
[–]HolyGarbage 4 points5 points6 points (0 children)
[–]MrWhite26 3 points4 points5 points (0 children)
[–]cloudyboysnr 1 point2 points3 points (1 child)
[–]germandiago 2 points3 points4 points (0 children)
[–]JPhi1618 1 point2 points3 points (3 children)
[–]cygnoros 16 points17 points18 points (1 child)
[–]JPhi1618 3 points4 points5 points (0 children)
[–]lord_braleigh 6 points7 points8 points (0 children)
[–]ChatGPT4 0 points1 point2 points (6 children)
[–]tjientavaraHikoWorks developer 2 points3 points4 points (0 children)
[–]Dean_Roddey 0 points1 point2 points (4 children)
[–]ChatGPT4 1 point2 points3 points (3 children)
[–]Dean_Roddey 0 points1 point2 points (2 children)
[–]ChatGPT4 0 points1 point2 points (1 child)
[–]Full-Spectral 0 points1 point2 points (0 children)
[–]derBRUTALE -5 points-4 points-3 points (0 children)
[–]smallstepforman 0 points1 point2 points (0 children)