Test.cxx 977 B

123456789101112131415161718192021222324252627282930313233
  1. //===-- examples/clang-interpreter/Test.cxx - Clang C Interpreter Example -===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // Example throwing in and from the JIT (particularly on Win64).
  9. //
  10. // ./bin/clang-interpreter <src>/tools/clang/examples/clang-interpreter/Test.cxx
  11. #include <stdexcept>
  12. #include <stdio.h>
  13. static void ThrowerAnError(const char* Name) {
  14. throw std::runtime_error(Name);
  15. }
  16. int main(int argc, const char** argv) {
  17. for (int I = 0; I < argc; ++I)
  18. printf("arg[%d]='%s'\n", I, argv[I]);
  19. try {
  20. ThrowerAnError("In JIT");
  21. } catch (const std::exception& E) {
  22. printf("Caught: '%s'\n", E.what());
  23. } catch (...) {
  24. printf("Unknown exception\n");
  25. }
  26. ThrowerAnError("From JIT");
  27. return 0;
  28. }