📄 logginghandler.htm
字号:
cout << "Error msg = " << error.errmsg << endl;
cout << "Example = " << error.dataObj << endl;
}
}
</code></pre>
</p>
<p><pre><code><span class="codeComment">// Example Code Using LoggingHandler on an IndexedDBView
const TIMESTAMP_STRUCT then = {2000, 12, 15, 0, 0, 0, 0};
<span class="codeComment">// Example of using an IndexDBView to try to insert Example objects and print out
// any errors that occurred</span>
void IndexedViewExample()
{
typedef DBView<Example, ParamObjExample> DBV;
DBV view("DB_EXAMPLE", DefaultBCA<Example>(),
"WHERE INT_VALUE BETWEEN (?) AND (?) OR "
"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",
BPAExampleObj());
IndexedDBView<DBV> indexed_view(view, "PrimaryIndex; STRING_VALUE; UNIQUE AlternateIndex; EXAMPLE_LONG,
EXAMPLE_DATE", BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));
try
{
<span class="codeComment">// Insert new items into the container</span>
pair<IndexedDBView<DBV>::iterator, bool> ins_pr;
ins_pr = indexed_view.insert(Example(459, "Unique String #1", 3.4, 1, date_criteria));
cout << "insertion succeded = " << (ins_pr.second == true ? "true": "false") << endl;
ins_pr = indexed_view.insert(Example(311, "", 3.99, 91, then)); <span class="codeComment">// should fail on InsValidate()</span>
cout << "insertion succeded = " << (ins_pr.second == true ? "true": "false") << endl;
ins_pr = indexed_view.insert(Example(222, "Positron", -34.77, 29, then)); <span class="codeComment">// should fail (ditto)</span>
cout << "insertion succeded = " << (ins_pr.second == true ? "true": "false") << endl;
}
catch (...)
{
typedef LoggingHandler<Example, ParamObjExample>::LoggedTriple LoggedTriple;
<span class="codeComment">// retrieve the LoggingHandler object from the IndexedDBView</span>
LoggingHandler<Example, ParamObjExample> log_handler =
indexed_view.get_io_handler((LoggingHandler<Example, ParamObjExample> *) NULL);
<span class="codeComment">// the log is a vector of (error message, DataObj, ParamObj) triples,
// (error message, Example object, ParamObjExample object) in this case
// the error itself along with the relevant DataObj and ParamObj that resulted with
// the error</span>
vector<LoggedTriple> error_log = log_handler.GetLog();
<span class="codeComment">// nothing to do if no errors occurred</span>
if (error_log.empty())
return;
cout << "*** Error Log in IndexedViewExample(): " << error_log.size() << " errors recorded! ***"
<< endl;
<span class="codeComment">// print out the errors</span>
for (vector<LoggedTriple>::const_iterator log_it = error_log.begin();
log_it != error_log.end(); log_it++)
{
cout << "*** Error Log Entry ***" << endl;
cout << "* error message *" << endl;
cout << (*log_it).errmsg << endl;
cout << "* relevant Example object *" << endl;
cout << (*log_it).dataObj << endl;
}
}
}</pre>
</p>
<h3>Public Base Classes</h3>
<p>None.</p>
<h3>Template parameters</h3>
<table border="1">
<TBODY> <tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td valign="top"><tt>DataObj</tt> </td>
<td valign="top">The value type of objects in a <font
size="2" face="Courier New">DBView</font>. </td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top"><tt>ParamObj</tt> </td>
<td valign="top">The type of object used to specify the
postfix parameters to the <font size="2"
face="Courier New">DBView</font>.</td>
<td valign="top"><font size="2" face="Courier New">DefaultParamObj<DataObj></font>
</td>
</tr>
</TBODY></table>
<p> </p>
<h3>Notation</h3>
<table border="0">
<tr>
<td valign="top"><tt>X</tt> </td>
<td valign="top">A type that is a model of <font size="2"
face="Courier New">LoggingHandler</font></td>
</tr>
<tr>
<td valign="top"><tt>a</tt> </td>
<td valign="top">Object of type <tt>X</tt> </td>
</tr>
</table>
<h3>Expression semantics</h3>
<table border="1">
<tr>
<th>Name </th>
<th>Expression </th>
<th>Precondition </th>
<th>Semantics </th>
<th>Postcondition </th>
</tr>
<tr>
<td valign="top">Default constructor </td>
<td valign="top"><pre>X a()</pre>
</td>
<td valign="top"> </td>
<td valign="top">Construct the function object.</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">Copy constructor </td>
<td valign="top"><pre>X a(constX &b)</pre>
</td>
<td valign="top"> </td>
<td valign="top">Copy construct the <font size="2"
face="Courier New">LoggingHandler</font>.</td>
<td valign="top"> </td>
</tr>
<tr>
<td>Assignment Operator</td>
<td><font size="2" face="Courier New">X operator=(const X
&b)</font></td>
<td> </td>
<td>Assign the <font size="2" face="Courier New">LoggingHandler</font>.</td>
<td> </td>
</tr>
<tr>
<td valign="top">Log exception operator</td>
<td valign="top"><pre>dtl_ios_base::MeansOfRecovery operator()(RootException &ex, dtl_ios_base &base, DataObj &data, ParamObj &params)</pre>
</td>
<td valign="top"> </td>
<td valign="top">This operator takes references to the
thrown <font size="2" face="Courier New">RootException</font>
object, the <font size="2" face="Courier New">dtl_ios_base</font>
(iterator) which threw, and the <font size="2"
face="Courier New">DataObj </font>and <font size="2"
face="Courier New">ParamObj </font>relevant to the
exception. Logs the exception to the vector of<font
size="2" face="Courier New"> </font><font size="1"
face="Courier New">LoggedTriple's</font><font size="2"> </font>and
then tells the iterator to suppress the error (<font
size="2" face="Courier New">dtl_ios_base::SUPPRESS_ERROR</font>).
</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">Get <b>copy</b> of exception log</td>
<td valign="top"><pre>vector<LoggedTriple> GetLog() const</pre>
</td>
<td valign="top"> </td>
<td valign="top">Returns the logged exceptions as a
vector of <font size="1" face="Courier New">LoggedTriple's.</font>
Note that all copies of this handler share the same error log vector.</td>
<td valign="top"> </td>
</tr>
</table>
<p> </p>
<h3>See also</h3>
<p><a href="AlwaysThrowsHandler.htm"><font size="2"
face="Courier New">AlwaysThrowsHandler</font></a><font size="2"
face="Courier New">, </font><a href="IOHandler.htm"><font
size="2" face="Courier New">IOHandler</font></a><font size="2"
face="Courier New">, </font><a href="DBView.htm"><font size="2"
face="Courier New">DBView</font></a><font size="2"
face="Courier New">, </font><a href="IndexedDBView.htm"><font
size="2" face="Courier New">IndexedDBView</font></a><a
href="IndexedDBView.htm"><font size="2"><!--start footer--></font></a></p>
<p>
<hr>
<p><a href="index.htm"><img src="dtl_home.gif" alt="[DTL Home]"
width="54" height="54"></a> <br>
</p>
<p>Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -