blob: ba5044e358a9dc2a8142a80608bdf6cb57464b46 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) C++ to HTML Converter -->
<title>
bad_cast.cpp</title>
<link rel="stylesheet" href="../../../Documentation/Style/CXX.css" type="text/css"></head>
<body>
<pre>
<span class=comment>// file : Example/ExH/BadCast/bad_cast.cpp
// author : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2002-2003 Boris Kolpackov
// license : http://kolpackov.net/license.html
</span><span class=preprocessor>#include "Utility/ExH/System/Exception.hpp"
</span><span class=preprocessor>#include <iostream>
</span><span class=keyword>using </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>cerr</span><span class=special>;
</span><span class=keyword>using </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>endl</span><span class=special>;
</span><span class=keyword>struct </span><span class=identifier>A
</span><span class=special>{
</span><span class=keyword>virtual
</span><span class=special>~</span><span class=identifier>A</span><span class=special>() </span><span class=special>{}
</span><span class=special>};
</span><span class=keyword>struct </span><span class=identifier>B
</span><span class=special>{
</span><span class=keyword>void
</span><span class=identifier>foo </span><span class=special>() </span><span class=special>{}
</span><span class=special>};
</span><span class=keyword>void
</span><span class=identifier>foo </span><span class=special>() </span><span class=keyword>throw </span><span class=special>(</span><span class=identifier>Utility</span><span class=special>::</span><span class=identifier>ExH</span><span class=special>::</span><span class=identifier>System</span><span class=special>::</span><span class=identifier>Exception</span><span class=special>)
</span><span class=special>{
</span><span class=identifier>A </span><span class=identifier>a</span><span class=special>;
</span><span class=identifier>A</span><span class=special>& </span><span class=identifier>ar </span><span class=special>(</span><span class=identifier>a</span><span class=special>);
</span><span class=identifier>B</span><span class=special>& </span><span class=identifier>br </span><span class=special>(</span><span class=keyword>dynamic_cast</span><span class=special><</span><span class=identifier>B</span><span class=special>&> </span><span class=special>(</span><span class=identifier>ar</span><span class=special>));
</span><span class=identifier>br</span><span class=special>.</span><span class=identifier>foo </span><span class=special>();
</span><span class=special>}
</span><span class=keyword>int
</span><span class=identifier>main </span><span class=special>()
</span><span class=special>{
</span><span class=keyword>try
</span><span class=special>{
</span><span class=identifier>foo </span><span class=special>();
</span><span class=special>}
</span><span class=keyword>catch </span><span class=special>(</span><span class=identifier>Utility</span><span class=special>::</span><span class=identifier>ExH</span><span class=special>::</span><span class=identifier>System</span><span class=special>::</span><span class=identifier>Exception </span><span class=keyword>const</span><span class=special>& </span><span class=identifier>ex</span><span class=special>)
</span><span class=special>{
</span><span class=identifier>cerr </span><span class=special><< </span><span class=string>"Caught Utility::ExH::System::Exception: "
</span><span class=special><< </span><span class=identifier>ex</span><span class=special>.</span><span class=identifier>what </span><span class=special>()
</span><span class=special><< </span><span class=identifier>endl</span><span class=special>;
</span><span class=special>}
</span><span class=special>}
</span></pre>
</body>
</html>
<!-- $Id$ -->
|