DFX Extraction library v4.14.5
enabling applications to perform DFX blood flow analysis
DFXErrors.h
1 /*
2  * Copyright (c) 2016-2019, Nuralogix Corp.
3  * All Rights reserved
4  *
5  * THIS SOFTWARE IS LICENSED BY AND IS THE CONFIDENTIAL AND
6  * PROPRIETARY PROPERTY OF NURALOGIX CORP. IT IS
7  * PROTECTED UNDER THE COPYRIGHT LAWS OF THE USA, CANADA
8  * AND OTHER FOREIGN COUNTRIES. THIS SOFTWARE OR ANY
9  * PART THEREOF, SHALL NOT, WITHOUT THE PRIOR WRITTEN CONSENT
10  * OF NURALOGIX CORP, BE USED, COPIED, DISCLOSED,
11  * DECOMPILED, DISASSEMBLED, MODIFIED OR OTHERWISE TRANSFERRED
12  * EXCEPT IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF A
13  * NURALOGIX CORP SOFTWARE LICENSE AGREEMENT.
14  */
15 #pragma once
16 #ifndef LIBDFX_ERRORS_H
17 #define LIBDFX_ERRORS_H
18 
19 #include "dfxc/dfx_error.h"
20 #include <stdexcept>
21 
29 namespace dfx {
30 
34 struct Error {
35  Error()
36  : opaque(nullptr)
37  {
38  }
39 
40  ~Error()
41  {
42  if (opaque) {
43  dfx_error_destroy(opaque);
44  }
45  }
46 
47  dfx_error* opaque;
48 };
49 
53 class ThrowOnError {
54 public:
55  ~ThrowOnError() noexcept(false)
56  {
57  if (_error.opaque) {
58  throw std::runtime_error(dfx_error_message(_error.opaque));
59  }
60  }
61 
62  operator dfx_error**() { return &_error.opaque; }
63 
64 private:
65  struct Error _error;
66 };
67 
68 #ifdef DFX_DEBUG_DESKTOP
69 #include <iostream>
70 class LogOnError {
71 public:
72  LogOnError(std::ostream& os) : _os(os) {}
73  ~LogOnError()
74  {
75  if (_error.opaque) {
76  _os << _error.opaque << std::endl;
77  }
78  }
79 
80  operator dfx_error**() { return &_error.opaque; }
81 
82 private:
83  std::ostream& _os;
84  struct Error _error;
85 };
86 #endif
87 
88 } // namespace dfx
89 
90 #endif
dfx::ThrowOnError
Definition: DFXErrors.h:53
dfx::Error
Definition: DFXErrors.h:34
dfx::ConstraintResult::Error
@ Error
dfx
Definition: ChunkData.h:21