Index: /trunk/FACT++/src/Fits.cc
===================================================================
--- /trunk/FACT++/src/Fits.cc	(revision 10945)
+++ /trunk/FACT++/src/Fits.cc	(revision 10946)
@@ -265,47 +265,61 @@
 void Fits::Write(Converter* conv)
 {
-
-	fTable->makeThisCurrent();
-	int status(0);
-	if (fits_insert_rows(fTable->fitsPointer(), fNumRows, 1, &status))
-	{
-		ostringstream str;
-		str << "Could not insert row in file " << fFileName << ". cfitsio error code: " << status;
-		fMess->Error(str);
-	}
-	fNumRows++;
-
-	//the first standard variable is the current MjD
-	if (fEndMjD == 0)
-	{
-		double doubleValue = *static_cast<double*>(fStandardPointers[0]);// - fRefMjD;
-		WriteSingleHeaderKey("TSTART", doubleValue, "Time of the first received data");
-	}
-	fEndMjD = * static_cast<double*>(fStandardPointers[0]);
-			
-	//first copy the standard variables to the copy buffer
-	int shift = 0;
-
-	for (unsigned int i=0;i<fStandardNumBytes.size();i++)
-	{
-		const char * charSrc = static_cast<char*>(fStandardPointers[i]);
-		reverse_copy(charSrc, charSrc+fStandardNumBytes[i], &fCopyBuffer[shift]);
-		shift+= fStandardNumBytes[i];	
-	}
-
-	//now take care of the DIM data. The Converter is here for that purpose
-	conv->ToFits(static_cast<void*>(&fCopyBuffer[shift]), fDataPointer, fDataNumBytes);
-			 
-	//data copied to buffer, can write to fits
-   	fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status);
-	if (status)
-	{
-		char text[30];//max length of cfitsio error strings (from doc)
-		fits_get_errstatus(status, text);
-		ostringstream str;
-		str << "Error while writing FITS row in " << fFileName << ". Message: " << text << " [" << status << "]";
-		fMess->Error(str);	
-	}
-}
+    //first copy the standard variables to the copy buffer
+    int shift = 0;
+    for (unsigned int i=0;i<fStandardNumBytes.size();i++)
+    {
+        const char *charSrc = reinterpret_cast<char*>(fStandardPointers[i]);
+        reverse_copy(charSrc, charSrc+fStandardNumBytes[i], &fCopyBuffer[shift]);
+        shift += fStandardNumBytes[i];
+    }
+
+    try
+    {
+        //now take care of the DIM data. The Converter is here for that purpose
+        conv->ToFits(&fCopyBuffer[shift], fDataPointer, fDataNumBytes);
+    }
+    catch (const runtime_error &e)
+    {
+        ostringstream str;
+        str << fFileName << ": " << e.what();
+        fMess->Error(str);
+        return;
+    }
+
+    fTable->makeThisCurrent();
+
+    int status(0);
+    if (fits_insert_rows(fTable->fitsPointer(), fNumRows, 1, &status))
+    {
+        ostringstream str;
+        str << "Inserting row into " << fFileName << " failed (fits_insert_rows, rc=" << status << ")";
+        fMess->Error(str);
+        // FIXME: What is a proper action here?
+    }
+
+    fNumRows++;
+
+    //the first standard variable is the current MjD
+    if (fEndMjD == 0)
+    {
+        const double doubleValue = *reinterpret_cast<double*>(fStandardPointers[0]);
+        WriteSingleHeaderKey("TSTART", doubleValue,
+                             "Time of the first received data");
+    }
+    fEndMjD = *reinterpret_cast<double*>(fStandardPointers[0]);
+
+    //data copied to buffer, can write to fits
+    fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status);
+    if (status)
+    {
+        char text[30];//max length of cfitsio error strings (from doc)
+        fits_get_errstatus(status, text);
+        ostringstream str;
+        str << "Writing FITS row " << fNumRow << " in " << fFileName << ": " << text << " (file_write_tblbytes, rc=" << status << ")";
+        fMess->Error(str);
+        // FIXME: What is a proper action here?
+    }
+}
+
 // --------------------------------------------------------------------------
 //
