Fabrique

A build language for complex systems

 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
exceptions.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (c) 2013 Jonathan Anderson
4  * All rights reserved.
5  *
6  * This software was developed by SRI International and the University of
7  * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8  * ("CTSRD"), as part of the DARPA CRASH research programme.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef EXCEPTIONS_H
33 #define EXCEPTIONS_H
34 
35 #include "Support/Printable.h"
36 #include "Support/SourceLocation.h"
37 
38 #include <exception>
39 #include <memory>
40 #include <string>
41 
42 
43 namespace fabrique {
44 
45 
47 class AssertionFailure : public std::exception
48 {
49 public:
50  AssertionFailure(const std::string& condition,
51  const std::string& message = "");
52 
54 
55  virtual ~AssertionFailure();
56 
57  const char* what() const noexcept;
58  const std::string& condition() const noexcept { return condition_; }
59  const std::string& message() const noexcept { return message_; }
60 
61 private:
62  const std::string condition_;
63  const std::string message_;
64 };
65 
66 
68 class OSError : public std::exception, public Printable
69 {
70 public:
71  OSError(const std::string& message, const std::string& description);
72  OSError(const OSError&);
73  virtual ~OSError();
74 
75  virtual const std::string& message() const { return message_; }
76  virtual const std::string& description() const { return description_; }
77 
78  const char* what() const noexcept { return completeMessage_.c_str(); }
79  virtual void PrettyPrint(Bytestream&, size_t indent = 0) const;
80 
81 private:
82  const std::string message_;
83  const std::string description_;
84  const std::string completeMessage_;
85 };
86 
87 
88 
90 class UserError : public std::exception, public Printable
91 {
92 public:
93  UserError(const std::string& message);
94  UserError(const UserError&);
95  virtual ~UserError();
96 
97  virtual const std::string& message() const { return message_; }
98  const char* what() const noexcept { return message_.c_str(); }
99 
100  virtual void PrettyPrint(Bytestream&, size_t indent = 0) const override;
101 
102 private:
103  const std::string message_;
104 };
105 
106 
107 
108 class ErrorReport;
109 
112  : public std::exception, public HasSource, public Printable
113 {
114 public:
115  virtual ~SourceCodeException();
116 
117  const std::string& message() const;
118  virtual const char* what() const noexcept;
119 
120  virtual void PrettyPrint(Bytestream&, size_t indent = 0) const override;
121 
122 protected:
123  SourceCodeException(const std::string& message, const SourceRange&);
125 
126 private:
127  std::shared_ptr<ErrorReport> err_;
128 };
129 
130 
133 {
134 public:
135  SyntaxError(const std::string& message, const SourceRange&);
136  SyntaxError(const SyntaxError&);
137  virtual ~SyntaxError();
138 };
139 
142 {
143 public:
144  SemanticException(const std::string& message, const SourceRange&);
146  virtual ~SemanticException();
147 };
148 
149 }
150 
151 #endif
A thing that can be pretty-printed.
Definition: Printable.h:46
Declaration of the fabrique::Printable interface.
virtual void PrettyPrint(Bytestream &, size_t indent=0) const
Print a human-readable representation to an output stream and return that output stream.
Definition: exceptions.cc:73
Base class for exceptions related to invalid source code.
Definition: exceptions.h:111
An error in user input.
Definition: exceptions.h:90
Some code may choose to throw this exception rather than assert() out.
Definition: exceptions.h:47
An error that has an OS-specific description.
Definition: exceptions.h:68
A mixin type for something that has a location in source code.
Declaration of fabrique::HasSource, fabrique::SourceLocation and fabrique::SourceRange.
virtual void PrettyPrint(Bytestream &, size_t indent=0) const override
Print a human-readable representation to an output stream and return that output stream.
Definition: exceptions.cc:126
A non-exceptional representation of a problem in source code.
Definition: ErrorReport.h:45
virtual void PrettyPrint(Bytestream &, size_t indent=0) const override
Print a human-readable representation to an output stream and return that output stream.
Definition: exceptions.cc:96
A syntactic error is present in the Fabrique description.
Definition: exceptions.h:132
A ostream-like class that may support formatting.
Definition: Bytestream.h:43
A range of characters in source code.
A semantic error is present in the Fabrique description.
Definition: exceptions.h:141