Frederich Munch | 529ce72 | 2018-03-14 16:04:45 +0000 | [diff] [blame] | 1 | //===-- examples/clang-interpreter/Test.cxx - Clang C Interpreter Example -===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // Example throwing in and from the JIT (particularly on Win64). |
| 11 | // |
| 12 | // ./bin/clang-interpreter <src>/tools/clang/examples/clang-interpreter/Test.cxx |
| 13 | |
| 14 | #include <stdexcept> |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | static void ThrowerAnError(const char* Name) { |
| 18 | throw std::runtime_error(Name); |
| 19 | } |
| 20 | |
| 21 | int main(int argc, const char** argv) { |
| 22 | for (int I = 0; I < argc; ++I) |
| 23 | printf("arg[%d]='%s'\n", I, argv[I]); |
Michael Platings | 49af748 | 2018-11-19 12:16:05 +0000 | [diff] [blame] | 24 | |
Frederich Munch | 529ce72 | 2018-03-14 16:04:45 +0000 | [diff] [blame] | 25 | try { |
| 26 | ThrowerAnError("In JIT"); |
| 27 | } catch (const std::exception& E) { |
| 28 | printf("Caught: '%s'\n", E.what()); |
| 29 | } catch (...) { |
| 30 | printf("Unknown exception\n"); |
| 31 | } |
| 32 | ThrowerAnError("From JIT"); |
| 33 | return 0; |
| 34 | } |