LLVM 22.0.0git
Error.h
Go to the documentation of this file.
1//===- Error.h - system_error extensions for Object -------------*- C++ -*-===//
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//
9// This declares a new error_category for the Object library.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_OBJECT_ERROR_H
14#define LLVM_OBJECT_ERROR_H
15
17#include "llvm/Support/Error.h"
18#include <system_error>
19
20namespace llvm {
21
22class Twine;
23
24namespace object {
25
26LLVM_ABI const std::error_category &object_category();
27
40
41inline std::error_code make_error_code(object_error e) {
42 return std::error_code(static_cast<int>(e), object_category());
43}
44
45/// Base class for all errors indicating malformed binary files.
46///
47/// Having a subclass for all malformed binary files allows archive-walking
48/// code to skip malformed files without having to understand every possible
49/// way that a binary file might be malformed.
50///
51/// Currently inherits from ECError for easy interoperability with
52/// std::error_code, but this will be removed in the future.
53class LLVM_ABI BinaryError : public ErrorInfo<BinaryError, ECError> {
54 void anchor() override;
55public:
56 static char ID;
58 // Default to parse_failed, can be overridden with setErrorCode.
60 }
61};
62
63/// Generic binary error.
64///
65/// For errors that don't require their own specific sub-error (most errors)
66/// this class can be used to describe the error via a string message.
68 : public ErrorInfo<GenericBinaryError, BinaryError> {
69public:
70 static char ID;
71 GenericBinaryError(const Twine &Msg);
72 GenericBinaryError(const Twine &Msg, object_error ECOverride);
73 const std::string &getMessage() const { return Msg; }
74 void log(raw_ostream &OS) const override;
75private:
76 std::string Msg;
77};
78
79/// isNotObjectErrorInvalidFileType() is used when looping through the children
80/// of an archive after calling getAsBinary() on the child and it returns an
81/// llvm::Error. In the cases we want to loop through the children and ignore the
82/// non-objects in the archive this is used to test the error to see if an
83/// error() function needs to called on the llvm::Error.
85
89
90} // end namespace object.
91
92} // end namespace llvm.
93
94namespace std {
95template <>
96struct is_error_code_enum<llvm::object::object_error> : std::true_type {};
97}
98
99#endif
#define LLVM_ABI
Definition Compiler.h:213
void setErrorCode(std::error_code EC)
Definition Error.h:1199
Base class for user error types.
Definition Error.h:354
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
GenericBinaryError(const Twine &Msg)
Definition Error.cpp:65
const std::string & getMessage() const
Definition Error.h:73
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
Error createError(const Twine &Err)
Definition Error.h:86
std::error_code make_error_code(object_error e)
Definition Error.h:41
LLVM_ABI const std::error_category & object_category()
Definition Error.cpp:77
LLVM_ABI Error isNotObjectErrorInvalidFileType(llvm::Error Err)
isNotObjectErrorInvalidFileType() is used when looping through the children of an archive after calli...
Definition Error.cpp:82
This is an optimization pass for GlobalISel generic memory operations.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851