我有一个带有以下代码的函数:
if (!File::exists(i_filename)) throw new FileNotFoundException(i_filename);
我的 FileNotFoundException 看起来像这样 .h
#pragma once
#include <exception>
#include <string>
class FileNotFoundException : public std::exception {
public:
FileNotFoundException(const std::string &i_filename);
private:
std::string m_filename;
};
.cpp
#include "FileNotFoundException.h"
FileNotFoundException::FileNotFoundException(const std::string & i_filename) {
m_filename = i_filename;
// A message will be pushed to console & debug window, I first wanted to test
}
Unhandled Exception at 0x7432D8A8 in 2D Game.exe: Microsoft C++ Exception: FileNotFoundException at storage location 0x0018F5FC.
但是当我运行时Visual Studio 会告诉我throw new FileNotFoundException(i_filename);
有谁知道出了什么问题?抱歉,我之前从未创建过异常类。