无法处理模块中的自定义runtime_error

时间:2018-12-15 19:49:02

标签: c++ error-handling runtime-error

我正在尝试处理runtime_error,但是编译器说在此范围内未声明“ runtime_error”。我已经添加了“ std”命名空间。并包含错误。

这是错误:

In file included from ErrorHandlingModule.cpp:1: ErrorHandlingModule.h:7:25: error: ‘runtime_error’ was not declared in this scope int HandleRuntimeError(runtime_error theRuntimeError); ^~~~~~~~~~~~~ ErrorHandlingModule.cpp:22:54: error: ‘int fpErrorHandling::HandleRuntimeError(std::runtime_error)’ redeclared as different kind of symbol int HandleRuntimeError(runtime_error theRuntimeError){

ErrorHandlingModule.cpp:

#include "ErrorHandlingModule.h"
#include <iostream>
#include <exception>

namespace fpErrorHandling{
    using namespace std;

    void Initialize(void){
        cin.exceptions(cin.failbit);
    }

    short int HandleNaN_error(void){
        cerr<<"Input error. Not a number?"<<endl;
        cin.clear();

        char BadInput[5];
        cin>>BadInput;

        return 1;
    }

    int HandleRuntimeError(runtime_error theRuntimeError){
        cerr<<theRuntimeError.what()<<endl;

        return 1;
    }

}

ErrorHandlingModule.h:

#ifndef ErrorHandlingModuleH
#define ErrorHandlingModuleH

namespace fpErrorHandling{
    void Initialize(void);
    short int HandleNaN_error(void);
    int HandleRuntimeError(runtime_error theRuntimeError);
}

#endif

0 个答案:

没有答案