a naive question about the exception in fstream

From: Newsgroup - Ann (news_ann_at_yahoo.com)
Date: 10/29/03

  • Next message: Jerry Coffin: "Re: Need template for list of name/value pairs"
    Date: Tue, 28 Oct 2003 21:25:29 -0500
    
    

    The fstream is supposed to be a replacement of the stdio.h and the exception
    is supposed to be a replacement of the return error code. So how do I
    replace my old codes of the style:

    if (output = fopen(...) == NULL) {
        perror("...");
        exit(1);
    }

    by the C++ style? The only thing I can do now is like

    fstream output("...", ios_base::out);
    if (!output.is_open()) {
        cerr << "..." << endl;
        exit(1);
    }

    how do I use exception here? Or I should not?

    Ann


  • Next message: Jerry Coffin: "Re: Need template for list of name/value pairs"

    Relevant Pages

    • Re: a naive question about the exception in fstream
      ... > The fstream is supposed to be a replacement of the stdio.h and the ... > is supposed to be a replacement of the return error code. ... > how do I use exception here? ...
      (comp.lang.cpp)
    • Re: Structured exception information
      ... Doesn't feel as type-safe as advertised. ... What, _exactly_, will the handler do with the separate bits? ... Looking up the localized error message in the dictionary based on the *type-safe* error code that it got from the exception object, ... I'm looking forward to see a convincing solution for error code and the dictionary. ...
      (comp.lang.ada)
    • Re: Exception : an ugly grammer in programming
      ... machinism in programming languages. ... we return error code when we meet an error. ... But how about use exception in OOP? ... Exceptions originally were designed to handle unexpected conditions, ...
      (comp.lang.php)
    • Re: [PHP] Re: MySQL exceptions
      ... I don't think MySQL or even mysqli have any kind of exception throwing ... echo "Impossible connect to server."; ... completely before trying to use a dead connection. ... error code number would be encapsulated as an ...
      (php.general)
    • Exception : an ugly grammer in programming
      ... Yes, I'm doing PHP. ... machinism in programming languages. ... we return error code when we meet an error. ... But how about use exception in OOP? ...
      (comp.lang.php)

    Loading