代码之家  ›  专栏  ›  技术社区  ›  f-person

无法处理模块中的自定义运行时错误

  •  0
  • f-person  · 技术社区  · 7 年前

    我试图处理运行时错误,但编译器说,该运行时错误并没有在此范围内声明。我已经添加了“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){

    #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;
        }
    
    }
    

    错误处理模块.h:

    #ifndef ErrorHandlingModuleH
    #define ErrorHandlingModuleH
    
    namespace fpErrorHandling{
        void Initialize(void);
        short int HandleNaN_error(void);
        int HandleRuntimeError(runtime_error theRuntimeError);
    }
    
    #endif
    
    0 回复  |  直到 7 年前