this repo has no description
1/* Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) */
2#pragma once
3
4#include "globals.h"
5#include "runtime.h"
6
7namespace py {
8
9// Internal equivalent to PyErr_GivenExceptionMatches(): Return whether or not
10// given is a subtype of any of the BaseException subtypes in exc, which may
11// contain arbitrarily nested tuples.
12bool givenExceptionMatches(Thread* thread, const Object& given,
13 const Object& exc);
14
15// Create an exception of the given type, which should derive from
16// BaseException. If value is None, no arguments will be passed to the
17// constructor, if value is a tuple, it will be unpacked as arguments, and
18// otherwise it will be the single argument.
19RawObject createException(Thread* thread, const Type& type,
20 const Object& value);
21
22// Return the appropriate OSError subclass from the given errno_value. If a
23// corresponding subclass is not found in the mapping, return OSError.
24LayoutId errorLayoutFromErrno(int errno_value);
25
26// Internal equivalent to PyErr_NormalizeException(): If exc is a Type subtype,
27// ensure that value is an instance of it (or a subtype). If a new exception
28// with a traceback is raised during normalization traceback will be set to the
29// new traceback.
30void normalizeException(Thread* thread, Object* exc, Object* val,
31 Object* traceback);
32
33// Internal equivalents to PyErr_PrintEx(): Print information about the current
34// pending exception to sys.stderr, including any chained exceptions, and clear
35// the exception. For printPendingExceptionWithSysLastVars(), also set
36// sys.last{type,value,traceback} to the type, value, and traceback of the
37// exception, respectively.
38//
39// Any exceptions raised during the printing process are swallowed.
40void printPendingException(Thread* thread);
41void printPendingExceptionWithSysLastVars(Thread* thread);
42
43// Internal equivalent to PyErr_Display(): Print information about the given
44// exception and traceback to sys.stderr, including any chained exceptions.
45// Returns None on success or Error on failure.
46RawObject displayException(Thread* thread, const Object& value,
47 const Object& traceback);
48
49// Handle an uncaught SystemExit exception. Print information about the
50// exception and call std::exit() with a status code extracted from the
51// exception.
52void handleSystemExit(Thread* thread);
53
54void initializeExceptionTypes(Thread* thread);
55
56} // namespace py