Line | Count | Source |
1 | | //===- exception.h ----------------------------------------------*- C++ -*-===// |
2 | | /////////////////////////////////////////////////////////////////////////////// |
3 | | // // |
4 | | // exception.h // |
5 | | // Copyright (C) Microsoft Corporation. All rights reserved. // |
6 | | // This file is distributed under the University of Illinois Open Source // |
7 | | // License. See LICENSE.TXT for details. // |
8 | | // // |
9 | | /////////////////////////////////////////////////////////////////////////////// |
10 | | |
11 | | #pragma once |
12 | | |
13 | | #include "dxc/Support/ErrorCodes.h" |
14 | | #include "dxc/WinAdapter.h" |
15 | | #include <exception> |
16 | | #include <string> |
17 | | |
18 | | namespace hlsl { |
19 | | |
20 | | /// <summary> |
21 | | /// Exception stores off information about an error and its error message for |
22 | | /// later consumption by the hlsl compiler tools. |
23 | | /// </summary> |
24 | | struct Exception : public std::exception { |
25 | | /// <summary>HRESULT error code. Must be a failure.</summary> |
26 | | HRESULT hr; |
27 | | std::string msg; |
28 | | |
29 | 128 | Exception(HRESULT errCode) : hr(errCode) {} |
30 | | Exception(HRESULT errCode, const std::string &errMsg) |
31 | 44 | : hr(errCode), msg(errMsg) {} |
32 | | |
33 | | // what returns a formatted message with the error code and the message used |
34 | | // to create the message. |
35 | 42 | virtual const char *what() const throw() { return msg.c_str(); } |
36 | | }; |
37 | | |
38 | | } // namespace hlsl |