Index: trunk/Mars/mcore/fits.h
===================================================================
--- trunk/Mars/mcore/fits.h	(revision 17909)
+++ trunk/Mars/mcore/fits.h	(revision 17911)
@@ -61,4 +61,9 @@
         kCompUnknown,
         kCompFACT
+    };
+
+    enum fitsstate
+    {
+        throwbit = 8
     };
 
@@ -477,4 +482,13 @@
     };
 
+    void Exception(const std::string &txt)
+    {
+#ifdef __EXCEPTIONS
+        if (exceptions()&throwbit)
+            throw std::runtime_error(txt);
+#endif
+        gLog << ___err___ << "ERROR - " << txt << std::endl;
+    }
+
 protected:
     std::ofstream fCopy;
@@ -559,4 +573,6 @@
         if (!good())
             return;
+
+        EnableAddressExceptions();
 
         if (memcmp(simple, "SIMPLE  = ", 10))
@@ -697,7 +713,7 @@
         {
 #ifdef __EXCEPTIONS
-            throw std::runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
-#else
-            gLog << ___err___ << "ERROR - You are trying to read a compressed fits with the base fits class. Please use factfits instead." << std::endl;
+            throw std::runtime_error("Trying to read a compressed fits with the base fits class. Use factfits instead.");
+#else
+            gLog << ___err___ << "ERROR - Trying to read a compressed fits with the base fits class. Use factfits instead." << std::endl;
 #endif
             clear(rdstate()|std::ios::badbit);
@@ -711,7 +727,7 @@
         {
 #ifdef __EXCEPTIONS
-            throw std::runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
-#else
-            gLog << ___err___ << "ERROR - You are trying to read a compressed fits with the base fits class. Please use factfits instead." << std::endl;
+            throw std::runtime_error("Trying to read a compressed fits with the base fits class. Use factfits instead.");
+#else
+            gLog << ___err___ << "ERROR - Trying to read a compressed fits with the base fits class. Use factfits instead." << std::endl;
 #endif
             clear(rdstate()|std::ios::badbit);
@@ -853,4 +869,17 @@
     }
 
+    void EnableAddressExceptions(bool b=true)
+    {
+        if (b)
+            exceptions(iostate(throwbit));
+        else
+            exceptions(iostate(exceptions()&~throwbit));
+    }
+
+    void DisableAddressExceptions()
+    {
+        EnableAddressExceptions(false);
+    }
+
     void *SetPtrAddress(const std::string &name)
     {
@@ -859,10 +888,6 @@
             std::ostringstream str;
             str << "SetPtrAddress('" << name << "') - Column not found.";
-#ifdef __EXCEPTIONS
-            throw std::runtime_error(str.str());
-#else
-            gLog << ___err___ << "ERROR - " << str.str() << std::endl;
+            Exception(str.str());
             return NULL;
-#endif
         }
 
@@ -888,10 +913,6 @@
             std::ostringstream str;
             str << "SetPtrAddress('" << name << "') - Column not found.";
-#ifdef __EXCEPTIONS
-            throw std::runtime_error(str.str());
-#else
-            gLog << ___err___ << "ERROR - " << str.str() << std::endl;
+            Exception(str.str());
             return false;
-#endif
         }
 
@@ -901,10 +922,6 @@
             str << "SetPtrAddress('" << name << "') - Element size mismatch: expected "
                 << fTable.cols[name].size << " from header, got " << sizeof(T);
-#ifdef __EXCEPTIONS
-            throw std::runtime_error(str.str());
-#else
-            gLog << ___err___ << "ERROR - " << str.str() << std::endl;
+            Exception(str.str());
             return false;
-#endif
         }
 
@@ -914,10 +931,6 @@
             str << "SetPtrAddress('" << name << "') - Element count mismatch: expected "
                 << fTable.cols[name].num << " from header, got " << cnt;
-#ifdef __EXCEPTIONS
-            throw std::runtime_error(str.str());
-#else
-            gLog << ___err___ << "ERROR - " << str.str() << std::endl;
+            Exception(str.str());
             return false;
-#endif
         }
 
@@ -962,10 +975,6 @@
             std::ostringstream str;
             str <<"SetPtrAddress('" << name << "') - Column not found.";
-#ifdef __EXCEPTIONS
-            throw std::runtime_error(str.str());
-#else
-            gLog << ___err___ << "ERROR - " << str.str() << std::endl;
+            Exception(str.str());
             return false;
-#endif
         }
 
@@ -975,10 +984,6 @@
             str << "SetPtrAddress('" << name << "') - Element count mismatch: expected "
                 << fTable.cols[name].num << " from header, got " << cnt;
-#ifdef __EXCEPTIONS
-            throw std::runtime_error(str.str());
-#else
-            gLog << ___err___ << "ERROR - " << str.str() << std::endl;
+            Exception(str.str());
             return false;
-#endif
         }
 
