00001 #pragma ident "$Id: exceptiontest.cpp 1895 2009-05-12 19:34:29Z afarris $" 00002 00003 //============================================================================ 00004 // 00005 // This file is part of GPSTk, the GPS Toolkit. 00006 // 00007 // The GPSTk is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU Lesser General Public License as published 00009 // by the Free Software Foundation; either version 2.1 of the License, or 00010 // any later version. 00011 // 00012 // The GPSTk is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU Lesser General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public 00018 // License along with GPSTk; if not, write to the Free Software Foundation, 00019 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 // 00021 // Copyright 2006, The University of Texas at Austin 00022 // 00023 //============================================================================ 00024 00025 #include <iostream> 00026 #include <string> 00027 00028 #include "Exception.hpp" 00029 00035 using namespace std; 00036 00037 class TestException 00038 { 00039 public: 00040 NEW_EXCEPTION_CLASS(TE, gpstk::Exception); 00041 00042 int foo; 00043 00044 void funcie() throw(TE) 00045 { 00046 try { 00047 foo=1; 00048 if (foo-1==0) 00049 { 00050 TE e("Blarfo"); 00051 e.addLocation(FILE_LOCATION); 00052 throw e; 00053 } 00054 foo=4; 00055 } catch (TE& e) { 00056 e.addText("Ja mon"); 00057 e.addLocation(FILE_LOCATION); 00058 throw; 00059 } 00060 } 00061 }; 00062 00063 // returns 0 if all tests pass 00064 int main() 00065 { 00066 TestException a; 00067 try { 00068 a.funcie(); 00069 } catch (gpstk::Exception& e) { 00070 cout << "main " << e; 00071 } 00072 }
1.3.9.1