The Micro C++ Library
include/micxx/Exception.hxx File Reference

Declaration of class micxx::Exception and the macros __MICXXTRY__ and __MICXXEND__. More...

#include <micxx/Config.hxx>
#include <ostream>
#include <string>
#include <cstdarg>

Classes

class  micxx::Exception
 An Exception is able to represent an error code, a message text and a stack of exception causes. More...

Namespaces

namespace  micxx
 

The Micro C++ Library.


Defines

#define __MICXXTRY__
 This macro simply starts a nested try catch block.
#define __MICXXEND__
 This macro closes a nested try catch block that was previously started by __MICXXTRY__.

Functions

template<typename Stream >
Stream & operator<< (Stream &stream, const micxx::Exception &exception)
 Write an Exception to a std::ostream reference.

Detailed Description

Declaration of class micxx::Exception and the macros __MICXXTRY__ and __MICXXEND__.


Define Documentation

#define __MICXXEND__
Value:
}                                                              \
catch (const micxx::Exception & cause)                         \
{                                                              \
    throw micxx::Exception(__FILE__, __LINE__, cause,          \
                           cause.getCode(), __FUNCTION__);     \
}                                                              \
catch (const std::exception & cause)                           \
{                                                              \
    throw micxx::Exception(__FILE__, __LINE__, "from %s: %s",  \
                           __FUNCTION__, cause.what());        \
}                                                              \
catch (...)                                                    \
{                                                              \
    throw micxx::Exception(__FILE__, __LINE__, "from %s: %s",  \
                           __FUNCTION__, "unknown exception"); \
}

This macro closes a nested try catch block that was previously started by __MICXXTRY__.

All exceptions of a (derived) type

  • const micxx::Exception& and all of
  • const std::exception & and
  • all others are wrapped appropriately as causes into a micxx::Exception instance, which is finally (re-)thrown.
#define __MICXXTRY__
Value:
try                                                            \
{

This macro simply starts a nested try catch block.


Function Documentation

template<typename Stream >
Stream& operator<< ( Stream &  stream,
const micxx::Exception exception 
)

Write an Exception to a std::ostream reference.

{
    stream << exception.getName();
    if (exception.getFilename())
    {
        stream << "(" << exception.getFilename()
               << "," << exception.getLine()
               << ")";
    }
    if (exception.getCode())
    {
        stream << ": " << exception.getCode();
    }
    stream << std::endl << "\t";
    stream << exception.getMessage();
    if (exception.getCause())
    {
        stream << " caused by" << std::endl
               << *exception.getCause();
    }
    return stream;
}