I am using a try-catch block like this one:
try {
Texture heightmapTexture = Texture("Snow0101_7_M.jpg");
} catch (TextureLoadException exc) {
std::cout << exc.what() << std::endl;
}
The thing is that I need to reuse the variable heightmapTexture further in my program. So I realized I can't do that because of the scope. Should I put the rest of the program inside the scope? For me that doesn't make any sense.
I also can't declare the variable outside of the scope because I have to initialize it. It has a constructor that only receives a string as input.
What would be the best solution?
I realize that I could use a pointer, but I am trying to avoid that (I am not really good at preventing memory leaks).
EDIT: Sorry, I was declaring the variable as a class Heightmap, which is wrong!, it is a texture object. But the problem is the same.