Skip to content

Instantly share code, notes, and snippets.

@hexagit
Created July 20, 2018 08:09
Show Gist options
  • Save hexagit/49d198658641f0b04cf7b58b0d1e914d to your computer and use it in GitHub Desktop.
Save hexagit/49d198658641f0b04cf7b58b0d1e914d to your computer and use it in GitHub Desktop.
アクセス違反でゲームエンジンが落ちないようにしよう!例外を生成する
// 例外を生成する
struct ExceptionFactory
{
// アクセス違反を発生させる
static void AccessViolation()
{
PrintScope scope("AccessViolation");
*((int*)0) = 0;
}
// ゼロ除算を発生させる
static void DivideByZero()
{
PrintScope scope("DivideByZero");
int zero = 0;
// inf
std::cout << 1.0f / zero << std::endl;
// nan
std::cout << 0.0f / zero << std::endl;
// exception
std::cout << 1 / zero << std::endl;
}
// スタックオーバーフローを発生させる
static void StackOverflow()
{
PrintScope scope("StackOverflow");
struct RecursiveCall
{
static void Function()
{
Function();
}
};
RecursiveCall::Function();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment