Created
July 20, 2018 08:09
-
-
Save hexagit/49d198658641f0b04cf7b58b0d1e914d to your computer and use it in GitHub Desktop.
アクセス違反でゲームエンジンが落ちないようにしよう!例外を生成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 例外を生成する | |
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