1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : test_DSC_Exception.cxx
23 // Author : Eric Fayolle (EDF)
26 #include "DSC_Exception.hxx"
28 //Compiler ce fichier en mode _DEBUG_ et sans _DEBUG_
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) {
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;
50 void lanceException1_7() throw(Exp1) {
51 throw Exp1(LOC(OSS() << "Ceci est l'exeption 1_7"));
55 DSC_EXCEPTION_CXX(A,Exp1);
56 DSC_EXCEPTION_CXX(A,Exp2);
65 a.lanceException1_1();
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;
73 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
77 a.lanceException1_2();
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;
86 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
90 a.lanceException1_3();
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;
98 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
102 a.lanceException1_4();
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;
110 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
114 a.lanceException1_5();
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;
122 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
126 a.lanceException1_6();
128 catch ( SALOME_Exception ex ) {
129 std::cout << "Exception SALOME bien reçue" << std::endl;
130 std::cout << ex.what() << std::endl;
132 std::cout << "Exception ... reçue mais aurait dû recevoir Exception SALOME" << std::endl;
136 a.lanceException1_6();
138 catch ( const SALOME_Exception & ex ) {
139 std::cout << "Exception SALOME bien reçue" << std::endl;
140 std::cout << ex.what() << std::endl;
142 std::cout << "Exception ... reçue mais aurait dû recevoir Exception SALOME" << std::endl;
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;
154 std::cout << "Exception ... reçue mais aurait dû recevoir Exception DSC" << std::endl;