1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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
23 // File : test_DSC_Exception.cxx
24 // Author : Eric Fayolle (EDF)
27 #include "DSC_Exception.hxx"
29 //Compiler ce fichier en mode _DEBUG_ et sans _DEBUG_
38 // La salome exception ne permet pas de passer une chaine ""
39 void lanceException1_1() { throw Exp1("_");}
40 void lanceException1_2() { throw Exp1("Ceci est l'exception 1_2");}
41 void lanceException1_3() { throw Exp1(LOC("Ceci est l'exception 1_3"));}
42 void lanceException1_4() { throw Exp1(LOC(OSS() << "Ceci est l'exeption 1_4" )); }
43 void lanceException1_5() {
45 throw Exp1(LOC(OSS() << "Ceci est l'exeption 1_5 avec la valeur A : " << a )); }
46 void lanceException1_6() {
47 Exp1 exp1(LOC(OSS() << "Ceci est l'exeption 1_6"));
48 std::cout << "Affichage de exp1.what() dans lanceException1_6() " << exp1.what() << std::endl;
51 void lanceException1_7() {
52 throw Exp1(LOC(OSS() << "Ceci est l'exeption 1_7"));
56 DSC_EXCEPTION_CXX(A,Exp1)
57 DSC_EXCEPTION_CXX(A,Exp2)
66 a.lanceException1_1();
68 catch ( const A::Exp1 & ex ) {
69 std::cout << "Exception 1 bien reçue" << std::endl;
70 std::cout << ex.what() << std::endl;
71 } catch ( const DSC_Exception & dscE ) {
72 std::cout << "Exception DSC reçue mais aurait dû recevoir Exception 1" << std::endl;
74 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
78 a.lanceException1_2();
80 // Essai par valeur (ne pas faire çà !)
81 catch ( A::Exp1& ex ) {
82 std::cout << "Exception 1 bien reçue" << std::endl;
83 std::cout << ex.what() << std::endl;
84 } catch ( const DSC_Exception & dscE ) {
85 std::cout << "Exception DSC reçue mais aurait dû recevoir Exception 1" << std::endl;
87 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
91 a.lanceException1_3();
93 catch ( const A::Exp1 & ex ) {
94 std::cout << "Exception 1 bien reçue" << std::endl;
95 std::cout << ex.what() << std::endl;
96 } catch ( const DSC_Exception & dscE ) {
97 std::cout << "Exception DSC reçue mais aurait dû recevoir Exception 1" << std::endl;
99 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
103 a.lanceException1_4();
105 catch ( const A::Exp1 & ex ) {
106 std::cout << "Exception 1 bien reçue" << std::endl;
107 std::cout << ex.what() << std::endl;
108 } catch ( const DSC_Exception & dscE ) {
109 std::cout << "Exception DSC reçue mais aurait dû recevoir Exception 1" << std::endl;
111 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
115 a.lanceException1_5();
117 catch ( const A::Exp1 & ex ) {
118 std::cout << "Exception 1 bien reçue" << std::endl;
119 std::cout << ex.what() << std::endl;
120 } catch ( const DSC_Exception & dscE ) {
121 std::cout << "Exception DSC reçue mais aurait dû recevoir Exception 1" << std::endl;
123 std::cout << "Exception ... reçue mais aurait dû recevoir Exception 1" << std::endl;
127 a.lanceException1_6();
129 catch ( SALOME_Exception& ex ) {
130 std::cout << "Exception SALOME bien reçue" << std::endl;
131 std::cout << ex.what() << std::endl;
133 std::cout << "Exception ... reçue mais aurait dû recevoir Exception SALOME" << std::endl;
137 a.lanceException1_6();
139 catch ( const SALOME_Exception & ex ) {
140 std::cout << "Exception SALOME bien reçue" << std::endl;
141 std::cout << ex.what() << std::endl;
143 std::cout << "Exception ... reçue mais aurait dû recevoir Exception SALOME" << std::endl;
147 a.lanceException1_7();
148 } catch ( const DSC_Exception & ex ) {
149 std::cout << "Exception DSC bien reçue" << std::endl;
150 std::cout << ex.what() << std::endl;
151 } catch ( const SALOME_Exception & ex ) {
152 std::cout << "Exception SALOME reçue mais aurais dû recevoir une exception DSC" << std::endl;
153 std::cout << ex.what() << std::endl;
155 std::cout << "Exception ... reçue mais aurait dû recevoir Exception DSC" << std::endl;