/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_EXCEPTION_HPP
#define NMM_EXCEPTION_HPP NMM_EXCEPTION_HPP

#include "nmm/nmm_prefix.hpp"

#include <string>
#include <ostream>

namespace NMM
{
  /** An exception.
   * This is the base class of all exceptions that are thrown by NMM and which are not
   * serializable.
   *
   * Throwing an exception:
   * @code
   * // In all other functions
   * throw Exception("Brief error description");
   * @endcode
   *
   * Note that for exceptions which are used frequently and which carry additional information,
   * a subclass of this class should be defined.
   *
   * Catching an exception:
   * @code
   * try {
   *   // ...
   * }
   * catch(const Exception& e) {
   *   cerr << e << endl;
   *   // ...
   * }
   * @endcode
   */
  class Exception {
  private:
    std::string comment;        ///< Exception comment

  public:
    /** Default constructor.
     * The exception comment is "Exception".
     */
    Exception ()
    {
      comment = "Exception";
    }

    /** Constructor.
     *
     * @param s Exception comment
     */
    Exception (const std::string& s) 
    {
      comment = "Exception : " + s;
    }

    /** Copy constructor.
     *
     * @param exception Object to copy from
     */
    Exception(const Exception& exception) 
    {
      *this = exception;
    }

    /** Get the exception comment.
     *
     * @return Exception comment
     */
    inline const std::string& getComment()     const { return comment;}

    /** Set the exception comment.
     *
     * @param s Exception comment
     */
    inline void setComment(const std::string& s)     { comment = s; }

    /** Output operator for Exception.
     * This operator writes the exception comment to the output stream.
     *
     * @param os An output stream
     * @param e An exception
     */
    friend std::ostream & operator << (std::ostream & os, const Exception& e)
    {
      return os << e.getComment();
    }

  };

}

#include "nmm/nmm_suffix.hpp"

#endif 
