Thread overview
GUI and non-GUI stream usage?
Nov 17, 2007
Bill Baxter
Nov 18, 2007
Stewart Gordon
Nov 18, 2007
Bill Baxter
Nov 18, 2007
Bill Baxter
Nov 18, 2007
Kris
November 17, 2007
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.

Is there a good reason for it to behave the way it does?  Or should I file a bug on it?

(And Tango folks -- does Stdout in Tango throw exceptions when there's no console?)

--bb
November 18, 2007
"Bill Baxter" <dnewsgroup@billbaxter.com> wrote in message news:fhnqbq$1dns$1@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?

> 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.

Stewart.

-- 
My e-mail address is valid but not my primary mailbox.  Please keep replies on the 'group where everybody may benefit. 

November 18, 2007
Stewart Gordon wrote:
> "Bill Baxter" <dnewsgroup@billbaxter.com> wrote in message news:fhnqbq$1dns$1@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
November 18, 2007
Bill Baxter wrote:
>>> It seems all the dout, derr streams defined in std.cstream throw exceptions if they're unable to write their output.

Correction: I just realized that dout does *NOT* throw an exception, but derr does.  Whether exceptions should be thrown or not, that seems like inconsistent behavior to me.

> 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.

This does seem to work, for anyone who's interested.

version (Windows) {
    std.c.stdio.freopen("Nul", "w", derr.file);
}

And the exceptions go away.


In the bigger picture it would be nice if I could rebind dout and derr to a different Stream so that I could write a GUI StreamLogger class. From the rumblings I hear, I'm guessing that sort of thing is probably possible in Tango?

--bb
November 18, 2007
"Bill Baxter" <dnewsgroup@billbaxter.com> wrote
> In the bigger picture it would be nice if I could rebind dout and derr to a different Stream so that I could write a GUI StreamLogger class. From the rumblings I hear, I'm guessing that sort of thing is probably possible in Tango?

Aye, it is