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