外部声明对象初始化的异常处理

问题描述 投票:0回答:0

假设我有代码

// state.h
extern struct AppState {
  AppState() {
    throw std::runtime_error("The runtime error");
  }
} appState; 

// state.cpp
#include "state.h"
AppState appState = AppState();

如何捕捉在构建

appState
过程中抛出的异常?

既然有办法在这种情况下抛出异常,我想也有办法捕获它们。

c++ exception constructor extern throw
© www.soinside.com 2019 - 2024. All rights reserved.