CFx SDK Documentation  2023 SP0
DrxError.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef _TxError_h_Included_
25 #define _TxError_h_Included_
26 
27 
28 #include "OdError.h"
29 #include "OdErrorContext.h"
30 
31 #include "TD_PackPush.h"
32 
33 
34 
41 {
42  OdString m_strAppName;
43  int m_nAppErrCode;
44  OdString m_strDescription;
45 
46 public:
48  : m_strAppName(L"Unknown")
49  , m_nAppErrCode(0)
50  {}
51 
52 
54  {
55  m_strAppName = name;
56  m_nAppErrCode = nCode;
57  m_strDescription = desc;
58  return this;
59  }
60 
61 
68  {
69  if (!m_strDescription.isEmpty())
70  return m_strDescription;
71  else
72  return OdString().format(L"Tx application \"%ls\" error: %d", m_strAppName.c_str(), m_nAppErrCode);
73  }
74 
75  virtual OdResult code() const { return eTxError; }
76  virtual int txAppCode() const { return m_nAppErrCode; }
77  virtual OdString txAppName() const {return m_strAppName;}
78 };
79 
80 
81 
92 class TxError : public OdError
93 {
94 protected:
95  TxError( OdErrorContext* pCtx ) : OdError( pCtx )
96  {}
97 public:
101  TxError(const OdString& sAppName, int nCode, const OdString& desc = OdString::kEmpty)
102  : OdError(OdRxObjectImpl<TxErrorContext>::createObject()->
103  init(sAppName, nCode, desc))
104  {}
105 
107  {
108  return ((TxErrorContext*)context())->txAppName();
109  }
110 
111  int txAppCode() const
112  {
113  return ((TxErrorContext*)context())->txAppCode();
114  }
115 };
116 
117 
118 // Usage example:
119 /*
120 class MyAppError : public TxError
121 {
122 public:
123  MyAppError(int nCode) : TxError(L"MyApplication", nCode)
124  {}
125 };
126 
127 
128  pHostAppservices->warning(MyAppError(123));
129  or
130  throw(MyAppError(123));
131 */
132 
133 
134 #include "TD_PackPop.h"
135 
136 #endif
OdResult
Definition: OdResult.h:29
OdString OdString
Definition: OdString.h:1224
const OdErrorContext * context() const
static OdRxClass * desc()
const OdChar * c_str() const
Definition: OdString.h:200
bool isEmpty() const
Definition: OdString.h:141
OdString & format(const OdChar *formatString,...)
FIRSTDLL_EXPORT_STATIC static const OdString kEmpty
Definition: OdString.h:98
OdString description() const
Definition: DrxError.h:67
OdSmartPtr< OdErrorContext > init(const OdString &name, int nCode, const OdString &desc=OdString::kEmpty)
Definition: DrxError.h:53
virtual OdResult code() const
Definition: DrxError.h:75
virtual int txAppCode() const
Definition: DrxError.h:76
virtual OdString txAppName() const
Definition: DrxError.h:77
OdString txAppName() const
Definition: DrxError.h:106
TxError(const OdString &sAppName, int nCode, const OdString &desc=OdString::kEmpty)
Definition: DrxError.h:101
TxError(OdErrorContext *pCtx)
Definition: DrxError.h:95
int txAppCode() const
Definition: DrxError.h:111
GLuint const GLchar * name
Definition: gles2_ext.h:265