00001 /* Copyright (C) 2003-2008 Stefan Buehler <sbuehler@ltu.se> 00002 00003 This program is free software; you can redistribute it and/or modify it 00004 under the terms of the GNU General Public License as published by the 00005 Free Software Foundation; either version 2, or (at your option) any 00006 later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00016 USA. */ 00017 00027 #include <cstdlib> 00028 #include <stdexcept> 00029 #include "arts.h" 00030 #include "messages.h" 00031 00032 00041 void arts_exit(int status) 00042 { 00043 exit (status); 00044 } 00045 00047 00055 void arts_exit_with_error_message(const String& m) 00056 { 00057 #ifdef _OPENMP 00058 #pragma omp critical 00059 #endif 00060 { 00061 out0 << m << "\n" 00062 << "Stopping ARTS execution.\n" 00063 << "Goodbye.\n"; 00064 arts_exit(); // No argument means failure. 00065 } 00066 } 00067 00069 00080 void exit_or_rethrow(const String& m) 00081 { 00082 #ifdef _OPENMP 00083 // With OpenMP, we have to terminate the program, 00084 // because exceptions can not be thrown out of the 00085 // parallel region. 00086 arts_exit_with_error_message(m); 00087 #else 00088 // Without OpenMP, we can re-throw the exception, to 00089 // be handled higher up. This to preserve the 00090 // "robust" option in ybatchCalc. 00091 throw runtime_error(m); 00092 #endif 00093 }