throwing errors in derived streambufs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Saff

    throwing errors in derived streambufs

    I would like to be able to create a std::exception from a user-defined
    stream, like:

    error << "Error: " << filename_ << " not found!" << std::endl;

    I figured I would just create a simple streambuf that would store characters
    in a string until it received '\n' and then throw a std::exception with the
    contents of the string. However, this exception is caught in the stream
    implementation and translated into a badbit.

    Any suggestions on how to do this? Do I just need to avoid deriving from
    ostream and streambuf, and create a class with its own op <<?


  • Kevin Saff

    #2
    Re: throwing errors in derived streambufs


    "Kevin Saff" <google.com@kev in.saff.net> wrote in message
    news:HnsJyz.1np @news.boeing.co m...[color=blue]
    > I figured I would just create a simple streambuf that would store[/color]
    characters[color=blue]
    > in a string until it received '\n' and then throw a std::exception with[/color]
    the[color=blue]
    > contents of the string. However, this exception is caught in the stream
    > implementation and translated into a badbit.[/color]

    OK, just after posting this I realized all that was necessary was to call
    exceptions (std::ios::badb it) on the stream object. Sorry for the waste.


    Comment

    Working...