2 * Copyright 2012 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.
20 #include "folly/experimental/exception_tracer/ExceptionTracer.h"
23 throw std::runtime_error("hello");
26 void dumpExceptions(const char* prefix) {
27 std::cerr << "--- " << prefix << "\n";
28 auto exceptions = exception_tracer::getCurrentExceptions();
29 for (auto& exc : exceptions) {
30 std::cerr << exc << "\n";
38 } catch (const std::exception& e) {
39 dumpExceptions("foo: simple catch");
42 } catch (const std::exception& e) {
43 dumpExceptions("foo: catch, exception thrown from previous catch block");
52 dumpExceptions("baz: simple catch");
55 } catch (const std::exception& e) {
56 dumpExceptions("baz: catch rethrown exception");
61 void testExceptionPtr1() {
62 std::exception_ptr exc;
66 exc = std::current_exception();
70 std::rethrow_exception(exc);
72 dumpExceptions("std::rethrow_exception 1");
76 void testExceptionPtr2() {
77 std::exception_ptr exc;
79 throw std::out_of_range("x");
81 exc = std::current_exception();
85 std::rethrow_exception(exc);
87 dumpExceptions("std::rethrow_exception 2");
91 int main(int argc, char *argv[]) {