Quantcast
Channel: Forum Pasja Informatyki - Najnowsze pytania bez odpowiedzi
Viewing all articles
Browse latest Browse all 21942

Catch przychwytuje wyjątek mimo że wartość do sprawdzenie jest poprawna

$
0
0
#include "my_file.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdexcept>

int main()
{
    my_file file( "dane.txt" );
    if ( file.is_file_opened() )
    {
        std::cerr << "Plik nie istnieje"<< std::endl;
//        return 1;
    }
    if ( file.is_file_empty() )
    {
        std::cerr << "Plik jest pusty"<< std::endl;
//        return 1;
    }
    try
    {
        double budget = std::stod( file.add_budget() );
    }
    catch ( std::invalid_argument)
    {
        std::cerr << "Dane w pliku nie są liczbami"<< std::endl;
    }

    std::cout << "budrzet na starcie wynosi: "<< std::setprecision(2) << budget << std::endl;
    return 0;
}

Wiem że w budget jest warość 800 więc czemu dostaje invalid_argument?


Viewing all articles
Browse latest Browse all 21942