GUI and non-GUI stream usage?

Bill Baxter dnewsgroup at billbaxter.com
Sun Nov 18 12:28:55 PST 2007


Stewart Gordon wrote:
> "Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
> news:fhnqbq$1dns$1 at digitalmars.com...
>> It seems all the dout, derr streams defined in std.cstream throw 
>> exceptions if they're unable to write their output.
>>
>> I find that unexpected and quite annoying.  From my experience such IO 
>> stream classes for dealing with console IO always just ignore writes 
>> if there is no console attached.
> 
> Annoying purely because you're not used to it, or for some other reason?

It's annoying because it makes it difficult to write programs and 
libraries that can be used effectively either in a GUI or Console 
setting.  And, yes, also because C++ doesn't act that way, and it's not 
documented clearly under CFile's docs, so I didn't expect it and others 
probably won't expect it either.

Failing that, I guess if there's a way I can freopen stdout/stderr to 
/dev/null on Windows that will do it.  I'll give that a try.


>> Is there a good reason for it to behave the way it does?  Or should I 
>> file a bug on it?
> 
> It probably isn't a bug.  If an application can't write to a file or 
> external device when it needs to, it's a serious error.  To suppress the 
> error in the particular case where it's stdout or stderr you're writing 
> to would be an inconsistency.

All I know is that cout in C++ doesn't generate an exception when 
writing to cout in a GUI app.  I'm not sure how that happens or at what 
layer, but it doesn't.

--bb


More information about the Digitalmars-d-learn mailing list