diff --git a/common/exceptions.hh b/common/exceptions.hh
index 7a90857261d4922460ed557fdb6e093e5bff7693..f42b740cdf346008c7aaa1fc5e434624de2ae9b6 100644
--- a/common/exceptions.hh
+++ b/common/exceptions.hh
@@ -146,6 +146,19 @@ namespace Dune {
    */
   class MathError : public Exception {};
 
+  /*! default exception class for Range errors
+
+     This is the superclass for all errors which are caused because
+     the user tries to access data, that was not allocated before.
+     These can be problems like
+
+     - accessing array entries behind the last entry
+     - adding the fourth non zero entry in a sparse matrix
+       with only three non zero entries per row
+
+   */
+  class RangeError : public Exception {};
+
 } // end namespace
 
 #endif
diff --git a/fem/feop/spmatrix.cc b/fem/feop/spmatrix.cc
index 671bb38019b8bf7089b8d82f6488aef84b61115d..a4e97e5fa09a279e58c621a73a99e694a1e8e095 100644
--- a/fem/feop/spmatrix.cc
+++ b/fem/feop/spmatrix.cc
@@ -1,6 +1,8 @@
 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 // vi: set et ts=4 sw=2 sts=2:
 #include <cmath>
+#include <limits>
+#include <dune/common/exceptions.hh>
 
 namespace Dune
 {
@@ -184,8 +186,10 @@ namespace Dune
     int whichCol = colIndex(row,col);
     if(whichCol < 0)
     {
-      std::cerr << "Error in SparseRowMatrix::set: Entry (" << row << ", " << col << ") "
-                << "could neither be found nor newly allocated!\n";
+      DUNE_THROW(RangeError,
+                 "Error in SparseRowMatrix::set: Entry ("
+                 << row << ", " << col << ") "
+                 << "could neither be found nor newly allocated!");
     }
     else
     {
@@ -197,14 +201,19 @@ namespace Dune
   template <class T>
   void SparseRowMatrix<T>::add(int row, int col, const T& val)
   {
+    if (std::numeric_limits<T>::has_quiet_NaN &&
+        std::numeric_limits<T>::quiet_NaN() == val)
+      DUNE_THROW(MathError, "trying to add NAN to a matrix entry.");
     if(std::abs(val) < EPS)
       return;
 
     int whichCol = colIndex(row,col);
     if(whichCol < 0)
     {
-      std::cerr << "Error in SparseRowMatrix::add: Entry (" << row << ", " << col << ") "
-                << "could neither be found nor newly allocated!\n";
+      DUNE_THROW(RangeError,
+                 "Error in SparseRowMatrix::add: Entry ("
+                 << row << ", " << col << ") "
+                 << "could neither be found nor newly allocated!");
     }
     else
     {
@@ -219,8 +228,10 @@ namespace Dune
     int whichCol = colIndex(row,col);
     if(whichCol < 0)
     {
-      std::cerr << "Error in SparseRowMatrix::multScalar: Entry Entry (" << row << ", " << col << ") "
-                << "could neither be found nor newly allocated!\n";
+      DUNE_THROW(RangeError,
+                 "Error in SparseRowMatrix::multScalar: Entry Entry ("
+                 << row << ", " << col << ") "
+                 << "could neither be found nor newly allocated!");
     }
     else
     {
@@ -434,15 +445,21 @@ namespace Dune
 
 
   template <class T>
-  void SparseRowMatrix<T>::print(std::ostream& s) const
+  void SparseRowMatrix<T>::print(std::ostream& s, int width) const
   {
+    char txt[20];
     for(int row=0; row<dim_[0]; row++)
     {
       for(int col=0; col<dim_[1]; col++)
       {
-        s << (*this)(row,col) << " ";
+        T t = (*this)(row,col);
+        if (t == 0.0)
+          snprintf(txt, 20, "%*i.0 ", width+5, 0);
+        else
+          snprintf(txt, 20, "% 1.*e ", width, t);
+        s << txt;
       }
-      s << "\n";
+      s << std::endl;
     }
   }
 
@@ -495,7 +512,7 @@ namespace Dune
     // non zero values before this line
     nzval_.resize(dim_[0]+1);
     for (int i=0; i<nzval_.size(); i++)
-      nzval_[i] = 3*i;
+      nzval_[i] = nz_*i;
     // fill missing entries
     for (int row = 0; row < dim_[0]; row++)
     {
diff --git a/fem/feop/spmatrix.hh b/fem/feop/spmatrix.hh
index fd32fdb87c86fa3826bfefeacae7788db077a607..e94b127c65dde95b78f2f49b14d8a163bb2d5a94 100644
--- a/fem/feop/spmatrix.hh
+++ b/fem/feop/spmatrix.hh
@@ -209,7 +209,7 @@ namespace Dune
     SparseRowMatrix<T> applyFromLeftAndRightTo(const SparseRowMatrix<T>& A) const;
 
     //! Prints the complete matrix including the nonzero entries
-    void print (std::ostream& s) const;
+    void print (std::ostream& s, int width=3) const;
 
     //! Just prints the nonzero entries
     void printReal (std::ostream& s) const;