Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/kernel.git] / src / DSC / DSC_User / test_DSC_Exception.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : test_DSC_Exception.cxx
23 //  Author : Eric Fayolle (EDF)
24 //  Module : KERNEL
25 //
26 #include "DSC_Exception.hxx"
27
28 //Compiler ce fichier en mode _DEBUG_ et sans _DEBUG_
29 class A {
30
31 public:
32   DSC_EXCEPTION(Exp1);
33   DSC_EXCEPTION(Exp2);
34
35   A() {};
36   virtual ~A() {};
37   // La salome exception ne permet pas de passer une chaine ""
38   void lanceException1_1() throw(Exp1) { throw Exp1("_");}
39   void lanceException1_2() throw(Exp1) { throw Exp1("Ceci est l'exception 1_2");}
40   void lanceException1_3() throw(Exp1) { throw Exp1(LOC("Ceci est l'exception 1_3"));}
41   void lanceException1_4() throw(Exp1) { throw Exp1(LOC(OSS() << "Ceci est l'exeption 1_4" )); }
42   void lanceException1_5() throw(Exp1) { 
43     int a=1;
44     throw Exp1(LOC(OSS() << "Ceci est l'exeption 1_5 avec la valeur A : " << a )); }
45   void lanceException1_6() throw(Exp1) {
46     Exp1 exp1(LOC(OSS() << "Ceci est l'exeption 1_6"));
47     std::cout << "Affichage de exp1.what() dans lanceException1_6() " << exp1.what() << std::endl;
48     throw Exp1(exp1); 
49   }
50   void lanceException1_7() throw(Exp1) {
51     throw Exp1(LOC(OSS() << "Ceci est l'exeption 1_7"));
52    }
53 };
54
55 DSC_EXCEPTION_CXX(A,Exp1);
56 DSC_EXCEPTION_CXX(A,Exp2);
57
58
59 int main() {
60
61   A a;
62   
63
64   try {
65     a.lanceException1_1();
66   }
67   catch (  const A::Exp1  & ex ) {
68     std::cout << "Exception 1 bien reçue" << std::endl;
69     std::cout << ex.what() << std::endl;
70   } catch ( const DSC_Exception & dscE ) {
71     std::cout << "Exception DSC  reçue mais aurait dû recevoir Exception 1" << std::endl;
72   } catch ( ...) {
73     std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
74   }
75
76   try {
77     a.lanceException1_2();
78   }
79   // Essai par valeur (ne pas faire çà !)
80   catch (  A::Exp1  ex ) {
81     std::cout << "Exception 1 bien reçue" << std::endl;
82     std::cout << ex.what() << std::endl;
83   } catch ( const DSC_Exception & dscE ) {
84     std::cout << "Exception DSC  reçue mais aurait dû recevoir Exception 1" << std::endl;
85   } catch ( ...) {
86     std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
87   }
88
89   try {
90     a.lanceException1_3();
91   }
92   catch ( const A::Exp1 & ex ) {
93     std::cout << "Exception 1 bien reçue" << std::endl;
94     std::cout << ex.what() << std::endl;
95   } catch ( const DSC_Exception & dscE ) {
96     std::cout << "Exception DSC  reçue mais aurait dû recevoir Exception 1" << std::endl;
97   } catch ( ...) {
98     std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
99   }
100
101   try {
102     a.lanceException1_4();
103   }
104   catch ( const A::Exp1 & ex ) {
105     std::cout << "Exception 1 bien reçue" << std::endl;
106     std::cout << ex.what() << std::endl;
107   } catch ( const DSC_Exception & dscE ) {
108     std::cout << "Exception DSC  reçue mais aurait dû recevoir Exception 1" << std::endl;
109   } catch ( ...) {
110     std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
111   }
112
113   try {
114     a.lanceException1_5();
115   }
116   catch ( const A::Exp1 & ex ) {
117     std::cout << "Exception 1 bien reçue" << std::endl;
118     std::cout << ex.what() << std::endl;
119   } catch ( const DSC_Exception & dscE ) {
120     std::cout << "Exception DSC  reçue mais aurait dû recevoir Exception 1" << std::endl;
121   } catch ( ...) {
122     std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
123   }
124
125   try {
126     a.lanceException1_6();
127   }
128   catch ( SALOME_Exception ex ) {
129     std::cout << "Exception SALOME bien reçue" << std::endl;
130     std::cout << ex.what() << std::endl;
131   } catch ( ...) {
132     std::cout << "Exception ... reçue mais aurait dû recevoir Exception SALOME" << std::endl;
133   }
134
135   try {
136     a.lanceException1_6();
137   }
138   catch ( const SALOME_Exception & ex ) {
139     std::cout << "Exception SALOME bien reçue" << std::endl;
140     std::cout << ex.what() << std::endl;
141   } catch ( ...) {
142     std::cout << "Exception ... reçue mais aurait dû recevoir Exception SALOME" << std::endl;
143   }
144
145   try {
146     a.lanceException1_7();
147   } catch ( const DSC_Exception & ex ) {
148     std::cout << "Exception DSC bien reçue" << std::endl;
149     std::cout << ex.what() << std::endl;
150   } catch ( const SALOME_Exception & ex ) {
151     std::cout << "Exception SALOME reçue mais aurais dû recevoir une exception DSC" << std::endl;
152     std::cout << ex.what() << std::endl;
153   } catch ( ...) {
154     std::cout << "Exception ... reçue mais aurait dû recevoir Exception DSC" << std::endl;
155   }
156
157 };