FOX/ObjCryst++  1.10.X (development)
Exception.cpp
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin vincefn@users.sourceforge.net
3  2000-2001 University of Geneva (Switzerland)
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /*
20 * source file for LibCryst++ ObjCrystException class
21 *
22 */
23 
24 #include "ObjCryst/ObjCryst/General.h"
25 #include <iostream>
26 #include <ctime>
27 #include "ObjCryst/ObjCryst/IO.h"
28 
29 namespace ObjCryst
30 {
31 
32 bool ObjCrystException::verbose = true;
33 
34 ObjCrystException::ObjCrystException() : message()
35 {
36  if (ObjCrystException::verbose)
37  {
38  cout << "LibCryst ++ exception thrown!!" << endl;
39  }
40 }
41 
42 ObjCrystException::ObjCrystException(const string & _message)
43 {
44 
45  message = _message;
46  if (!ObjCrystException::verbose)
47  {
48  return;
49  }
50 
51  static bool inException;
52  cout << "LibCryst ++ exception thrown!!" << endl;
53  cout << " Message: " + message <<endl;
54  if(false==inException)
55  {
56  inException=true;
57  string saveFileName="ObjCryst";
58  time_t date=time(0);
59  char strDate[40];
60  strftime(strDate,sizeof(strDate),"%Y-%m-%d_%H-%M-%S",gmtime(&date));//%Y-%m-%dT%H:%M:%S%Z
61  saveFileName=saveFileName+strDate+".xml";
62  cout << "Attempting to save ObjCryst++ environment to file:"<<saveFileName<<endl;
63  try
64  {
65  XMLCrystFileSaveGlobal(saveFileName);
66  }
67  catch(...)
68  {cout<<"Sorry, failed to save ObjCryst++ environment"<<endl;}
69  inException=false;
70  }
71 }
72 
73 ObjCrystException::~ObjCrystException(){}
74 
75 //######################################################################
76 void (*fpObjCrystInformUser)(const string &)=ObjCrystInformUserStdOut;
77 
78 void ObjCrystInformUserStdOut(const string &str)
79 {
80  cout <<str<<endl;
81 }
82 
83 }//namespace
84 
85 
void ObjCrystInformUserStdOut(const string &str)
Print some information for the user during long processes.
Definition: Exception.cpp:78
void XMLCrystFileSaveGlobal(const string &filename)
Save all Objcryst++ objects.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47