1 /*++
2 Copyright (c) 2006 Microsoft Corporation
3 
4 Module Name:
5 
6     ex.cpp
7 
8 Abstract:
9 
10     <abstract>
11 
12 Author:
13 
14     Leonardo de Moura (leonardo) 2011-04-28
15 
16 Revision History:
17 
18 --*/
19 #include<iostream>
20 #include "util/z3_exception.h"
21 
22 class ex {
23 public:
~ex()24     virtual ~ex() {}
25     virtual char const * msg() const = 0;
26 };
27 
28 class ex1 : public ex {
29     char const * m_msg;
30 public:
ex1(char const * m)31     ex1(char const * m):m_msg(m) {}
msg() const32     char const * msg() const override { return m_msg; }
33 };
34 
35 class ex2 : public ex {
36     std::string m_msg;
37 public:
ex2(char const * m)38     ex2(char const * m):m_msg(m) {}
msg() const39     char const * msg() const override { return m_msg.c_str(); }
40 };
41 
th()42 static void th() {
43     throw ex2("testing exception");
44 }
45 
tst1()46 static void tst1() {
47     try {
48         th();
49     }
50     catch (ex & e) {
51         std::cerr << e.msg() << "\n";
52     }
53 }
54 
tst2()55 static void tst2() {
56     try {
57         throw default_exception(default_exception::fmt(), "Format %d %s", 12, "twelve");
58     }
59     catch (z3_exception& ex) {
60         std::cerr << ex.msg() << "\n";
61     }
62 }
63 
tst_ex()64 void tst_ex() {
65     tst1();
66     tst2();
67 }
68