wxFileInputStream File Not Found Error

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Lowkus
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sun May 01, 2016 2:48 am

wxFileInputStream File Not Found Error

Post by Lowkus »

I instantiate a wxFileInputStream object giving it a filename that doesn't exist:

wxFileInputStream fizzy5(fdlg->GetPath());

At the point the wxFileInputStream object is destroyed it always throws this message box:
"Can't open file 'C:\somefilename' (error 2: the system cannot find the file specified.)"

Is there a way to not have the message box appear?

I am also wondering, what is the proper way to forcefully destroy fizzy5 when I'm done with it?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxFileInputStream File Not Found Error

Post by PB »

Lowkus wrote:Is there a way to not have the message box appear?
Use wxLogNull. Check the docs to see how it works to avoid possible side effects
Lowkus wrote:I am also wondering, what is the proper way to forcefully destroy fizzy5 when I'm done with it?
Call the dtor directly? But that is somewhat unusual so perhaps it would be better to create it on heap instead of stack so you can delete it...

IMO, if possible, it would be best to use a small scope which would take care of both issues.

Code: Select all

{
    wxLogNull logNo;
    wxFileInputStream fizzy5(fdlg->GetPath());
    
    // read from the stream
    
} // logging re-enabled and stream destroyed here
Post Reply