2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <folly/experimental/exception_tracer/ExceptionTracer.h>
24 throw std::runtime_error("hello");
27 void dumpExceptions(const char* prefix) {
28 std::cerr << "--- " << prefix << "\n";
29 auto exceptions = ::folly::exception_tracer::getCurrentExceptions();
30 for (auto& exc : exceptions) {
31 std::cerr << exc << "\n";
39 } catch (const std::exception& e) {
40 dumpExceptions("foo: simple catch");
43 } catch (const std::exception& e) {
44 dumpExceptions("foo: catch, exception thrown from previous catch block");
53 dumpExceptions("baz: simple catch");
56 } catch (const std::exception& e) {
57 dumpExceptions("baz: catch rethrown exception");
62 void testExceptionPtr1() {
63 std::exception_ptr exc;
67 exc = std::current_exception();
71 std::rethrow_exception(exc);
73 dumpExceptions("std::rethrow_exception 1");
77 void testExceptionPtr2() {
78 std::exception_ptr exc;
80 throw std::out_of_range("x");
82 exc = std::current_exception();
86 std::rethrow_exception(exc);
88 dumpExceptions("std::rethrow_exception 2");
92 int main(int /* argc */, char* /* argv */ []) {