Fawkes API  Fawkes Development Version
fawkes::Exception Class Reference

Base class for exceptions in Fawkes. More...

#include <core/exception.h>

Inherits std::exception.

Inherited by DirectRobotinoComMessage::ChecksumError, fawkes::AccessViolationException, fawkes::BBInconsistentMemoryException, fawkes::BBMemMgrCannotOpenException, fawkes::BBNotMasterException, fawkes::BlackBoardInterfaceNotFoundException, fawkes::BlackBoardInterfaceVersionMismatchException, fawkes::BlackBoardMemMgrInvalidPointerException, fawkes::BlackBoardNoMasterAliveException, fawkes::BlackBoardNoWritingInstanceException, fawkes::BlackBoardWriterActiveException, fawkes::CannotEnableMirroringException, fawkes::CannotFinalizeThreadException, fawkes::CannotInitializeThreadException, fawkes::ConfigEntryNotFoundException, fawkes::ConfigTypeMismatchException, fawkes::ConfigurationException, fawkes::ConnectionDiedException, fawkes::CouldNotOpenConfigException, fawkes::CouldNotOpenFileException, fawkes::DependencyViolationException, fawkes::DestructionInProgressException, fawkes::DivisionByZeroException, fawkes::FawkesNetworkMessageTooBigException, fawkes::FileReadException, fawkes::FileWriteException, fawkes::HandlerAlreadyRegisteredException, fawkes::IllegalArgumentException, fawkes::InterfaceInvalidException, fawkes::InterfaceInvalidMessageException, fawkes::InterfaceMessageEnqueueException, fawkes::InterfaceWriteDeniedException, fawkes::InterruptedException, fawkes::KatanaMotorCrashedException, fawkes::KatanaNoSolutionException, fawkes::KatanaOutOfRangeException, fawkes::KatanaUnsupportedException, fawkes::KDLParserModelGenerationFailedException, fawkes::KDLParserUnknownJointTypeException, fawkes::LuaErrorException, fawkes::LuaRuntimeException, fawkes::MessageAlreadyQueuedException, fawkes::MessageDecryptionException, fawkes::MessageEncryptionException, fawkes::MessageTooBigException, fawkes::MissingArgumentException, fawkes::MissingParameterException, fawkes::ModuleOpenException, fawkes::NonPointerTypeExpectedException, fawkes::NotImplementedException, fawkes::NotLockedException, fawkes::NullPointerException, fawkes::OutOfBoundsException, fawkes::OutOfMemoryException, fawkes::PluginLoadException, fawkes::PluginUnloadException, fawkes::SemCannotLockException, fawkes::SemCannotSetValException, fawkes::SemCannotUnlockException, fawkes::SemInvalidException, fawkes::ShmAddrOutOfBoundsException, fawkes::ShmCouldNotAttachAddrDepException, fawkes::ShmCouldNotAttachException, fawkes::ShmDoesNotExistException, fawkes::ShmInconsistentSegmentSizeException, fawkes::ShmNoHeaderException, fawkes::ShmPtrOutOfBoundsException, fawkes::SocketException, fawkes::SyntaxErrorException, fawkes::tf::TransformException, fawkes::ThreadListNotSealedException, fawkes::ThreadListSealedException, fawkes::TimeoutException, fawkes::TypeMismatchException, fawkes::UnableToOpenFileException, fawkes::UniquenessViolationException, fawkes::UnknownArgumentException, fawkes::UnknownLoggerTypeException, fawkes::UnknownTypeException, fawkes::URDFColladaNotSupportedException, fawkes::URDFXMLDocumentParseErrorException, fawkes::URDFXMLElementParseErrorException, firevision::CameraNotOpenedException, firevision::CameraNotStartedException, firevision::CaptureException, firevision::InconsistentImageException, firevision::InconsistentLUTException, firevision::UnknownCameraControlTypeException, firevision::UnknownCameraException, firevision::UnknownCameraTypeException, firevision::ViscaControlException, InterfaceGeneratorAmbiguousNameException, InterfaceGeneratorInvalidAttributeException, InterfaceGeneratorInvalidContentException, InterfaceGeneratorInvalidDocumentException, InterfaceGeneratorInvalidFlagException, InterfaceGeneratorInvalidTypeException, InterfaceGeneratorInvalidValueException, InterfaceGeneratorMissingAttributeException, and ViscaException.

Classes

class  iterator
 Message iterator for exceptions. More...
 
struct  message_list_t
 Internal exception message list. More...
 

Public Member Functions

 Exception (const char *format,...) throw ()
 Constructor. More...
 
 Exception (int errnoval, const char *format,...) throw ()
 Constructor. More...
 
 Exception (const Exception &exc) throw ()
 Copy constructor. More...
 
virtual ~Exception () throw ()
 Destructor. More...
 
virtual void raise ()
 This can be used to throw this exception. More...
 
void prepend (const char *format,...) throw ()
 Prepend messages to the message list. More...
 
void append (const char *format,...) throw ()
 Append messages to the message list. More...
 
void append_va (const char *format, va_list va) throw ()
 Append messages to the message list. More...
 
void append (const Exception &e) throw ()
 Append message that are from another Exception. More...
 
void print_trace () throw ()
 Prints trace to stderr. More...
 
void print_backtrace () const throw ()
 Prints a backtrace. More...
 
char * generate_backtrace () const throw ()
 Generate backtrace string. More...
 
int get_errno () throw ()
 Get errno. More...
 
void set_type_id (const char *id)
 Set exception type ID. More...
 
const char * type_id () const
 Get type ID. More...
 
virtual const char * what () const throw ()
 Get primary string. More...
 
virtual const char * what_no_backtrace () const throw ()
 Get primary string (does not implicitly print the back trace). More...
 
Exceptionoperator= (const Exception &exc) throw ()
 Assign an Exception. More...
 
iterator begin () throw ()
 Get iterator for messages. More...
 
iterator end () throw ()
 Get end iterator for messages. More...
 

Protected Member Functions

 Exception () throw ()
 Constructor for subclasses. More...
 
void append_nolock (const char *format,...) throw ()
 Append messages without lock. More...
 
void append_nolock_va (const char *format, va_list va) throw ()
 Append messages without lock by formatted string. More...
 
void append_nolock_nocopy (char *msg) throw ()
 Append message without copying. More...
 
void prepend_nolock_va (const char *format, va_list va) throw ()
 Prepend messages without lock by formatted string. More...
 
void copy_messages (const Exception &exc) throw ()
 Copy messages from given exception. More...
 

Protected Attributes

message_list_tmessages
 List of messages. More...
 
message_list_tmessages_iterator
 Iterator to iterate over messages. More...
 
message_list_tmessages_end
 Pointer that points to the very last message. More...
 
Mutexmessages_mutex
 Mutex to protect operations on messages list. More...
 
int _errno
 Error number, should be used if the error was caused by a method that supplies errno. More...
 

Detailed Description

Base class for exceptions in Fawkes.

Exceptions are a good way to handle errors. If you choose to use exceptions use derivates of this class so that there is a unified way of handling errors in Fawkes. Do not throw an arbitrary class such as a string or integer as this is hard to handle.

For your exceptions in general you only need to override the constructor and call the Exception constructor with the appropriate message. In cases where more information is needed about the error add appropriate handlers.

In most cases it is bad to just throw an Exception like this:

if ( error_condition ) {
throw Exception("Out of memory");
}

Rather you should explicitly subclass Exception appropriately. For the above example you could have something like this as exception class:

class OutOfMemException : public Exception
{
public:
OutOfMemoryException() : Exception("Out of memory") {}
}

And in your handling code you throw a OutOfMemoryException. This is especially useful if it is possible to throw several different exceptions. If the message was different you would have to parse the string for the exact error. This can be avoided if you just catch different exceptions. This is also useful if the Exception is not catched explicitly as this will printout the name of the exception class thrown just before exiting the program. And reading something like "terminate called after throwing an instance of 'OutOfMemoryException'" makes it a lot easier to spot the problem.

Exceptions should be catched by reference like this:

try {
some_operation();
} catch (OutOfMemoryException &e) {
std::cout << e.c_str() << std::endl;
error_handling();
}

Messages are stored as list. The first message however is called the primary message and it should contain as much information as available. This message is printed on the screen if the application crashes with an unhandled exception. So having meaningful content here means that the error can be traced more easily.

You can utilize the list feature by adding appropriate information through appropriate try/catch statements. This way you can build information path ways that will help to debug your software. Use block like this to append information:

try {
potentially_failing();
} catch {MyException &e) {
e.append("info where exception happened");
throw; // re-throw exception
}

This is especially useful if the exception may occur at several different places and it cannot be fixed where it happens.

See also
example_exception.cpp
Author
Tim Niemueller

Definition at line 36 of file exception.h.

Constructor & Destructor Documentation

◆ Exception() [1/4]

fawkes::Exception::Exception ( const char *  format,
  ... 
)
throw (
)

Constructor.

Constructs a new exception with the given message.

Parameters
formatThe format of the primary message. Supports the same arguments as append(). The message is copied and not just referenced. Thus the memory has to be freed if it is a dynamic string on the heap.

Definition at line 145 of file exception.cpp.

References _errno, append_nolock(), append_nolock_va(), messages, messages_end, messages_iterator, and messages_mutex.

◆ Exception() [2/4]

fawkes::Exception::Exception ( int  errnoval,
const char *  format,
  ... 
)
throw (
)

Constructor.

Constructs a new exception with the given message and errno value. This is particularly handy when throwing the exception after a function failed that returns an error code in errno.

Parameters
errnovalerror number
formatThe format of the primary message. Supports the same arguments as append(). The message is copied and not just referenced. Thus the memory has to be freed if it is a dynamic string on the heap.

Definition at line 176 of file exception.cpp.

References _errno, append_nolock(), append_nolock_va(), messages, messages_end, messages_iterator, and messages_mutex.

◆ Exception() [3/4]

fawkes::Exception::Exception ( const Exception exc)
throw (
)

Copy constructor.

The copy constructor is worth some extra discussion. If you do an exception by value (which you shouldn't in the first place since this will generate a copy, only do this if you can't avoid it for some reason. Not if you only THINK that you can't avoid it) the copy constructor is called. If your catch statements reads like

try {
...
} catch (Exception e) {
...
}

then a copy will be created for the catch block. You throw the exception with something like

throw Exception("Boom");

This will create an Exception which is valid in the block where you throw the exception. Now for the catch block a copy is created. Since the exception holds a pointer on the heap the implicit copy constructor would just copy the pointer, not the data. So both exceptions point to the same data (to the message for the base exception). If now both destructors for the exception are called they both try to free the very same memory. Of course the second destructor will cause a disaster. If you are lucky your glibc detectes the problem an kills the application. If you are not that fortunate you will cause very strange behaviour of your application.

In general you should not have to worry about this. But if you choose to have own storage on the heap using either new, malloc or a method that returns memory on the heap (like strdup()) you have to write your own copy contructor and copy the memory area or take care that only one exception frees the memory.

Parameters
excException to copy

Definition at line 238 of file exception.cpp.

References _errno, copy_messages(), messages, messages_end, messages_iterator, and messages_mutex.

◆ ~Exception()

fawkes::Exception::~Exception ( )
throw (
)
virtual

◆ Exception() [4/4]

Member Function Documentation

◆ append() [1/2]

void fawkes::Exception::append ( const char *  format,
  ... 
)
throw (
)

Append messages to the message list.

Parameters
formatformat of the message to append, see printf(3) for details about formatting options.

Definition at line 341 of file exception.cpp.

References append_nolock_va(), fawkes::Mutex::lock(), messages_mutex, and fawkes::Mutex::unlock().

Referenced by BatteryMonitorTreeView::add_host(), Visca::apply_effect(), Visca::apply_effect_bnw(), Visca::apply_effect_mosaic(), Visca::apply_effect_neg_art(), Visca::apply_effect_pastel(), Visca::apply_effect_sepia(), Visca::apply_effect_slim(), Visca::apply_effect_solarize(), Visca::apply_effect_stretch(), firevision::ViscaControl::applyEffect(), firevision::ViscaControl::applyEffectBnW(), firevision::ViscaControl::applyEffectMosaic(), firevision::ViscaControl::applyEffectNegArt(), firevision::ViscaControl::applyEffectPastel(), firevision::ViscaControl::applyEffectSepia(), firevision::ViscaControl::applyEffectSlim(), firevision::ViscaControl::applyEffectSolarize(), firevision::ViscaControl::applyEffectStretch(), fawkes::BBInconsistentMemoryException::BBInconsistentMemoryException(), fawkes::BBNotMasterException::BBNotMasterException(), BlackBoardLoggerPlugin::BlackBoardLoggerPlugin(), BlackBoardLogReplayPlugin::BlackBoardLogReplayPlugin(), fawkes::BlackBoardNoWritingInstanceException::BlackBoardNoWritingInstanceException(), fawkes::BlackBoardWriterActiveException::BlackBoardWriterActiveException(), firevision::ViscaControl::cancel_command(), Visca::cancel_command(), firevision::Bumblebee2Camera::capture(), firevision::ViscaControl::clear(), Visca::clear(), fawkes::ConfigTypeMismatchException::ConfigTypeMismatchException(), fawkes::ConfigurationException::ConfigurationException(), fawkes::ConnectionDiedException::ConnectionDiedException(), DynamixelChain::discover(), RobotisRX28::discover(), fawkes::FawkesNetworkMessageTooBigException::FawkesNetworkMessageTooBigException(), fawkes::VisionAspectIniFin::finalize(), fawkes::LoggerAspectIniFin::finalize(), fawkes::TimeSourceAspectIniFin::finalize(), fawkes::VisionMasterAspectIniFin::finalize(), fawkes::MainLoopAspectIniFin::finalize(), fawkes::ThreadList::finalize(), fawkes::ThreadList::force_stop(), FireVisionNetworkTool::fuse_inbound_received(), fawkes::NetworkConfiguration::get_bool(), fawkes::NetworkConfiguration::get_comment(), fawkes::NetworkConfiguration::get_default_comment(), fawkes::NetworkConfiguration::get_float(), fawkes::NetworkConfiguration::get_int(), Visca::get_mirror(), fawkes::SQLiteConfiguration::get_string(), fawkes::NetworkConfiguration::get_string(), fawkes::NetworkConfiguration::get_uint(), fawkes::NetworkConfiguration::get_value(), Visca::get_white_balance_mode(), Firestation::get_window(), Visca::get_zoom(), firevision::ViscaControl::getWhiteBalanceMode(), firevision::ViscaControl::getZoom(), fawkes::VisionAspectIniFin::init(), fawkes::LoggerAspectIniFin::init(), fawkes::VisionMasterAspectIniFin::init(), ExampleBlackBoardThread::init(), HokuyoUrgAcquisitionThread::init(), FvSrSavePipelineThread::init(), fawkes::MainLoopAspectIniFin::init(), RosNavgraphBreakoutThread::init(), JoystickAcquisitionThread::init(), RosNavigatorThread::init(), BlackBoardSynchronizationThread::init(), FvRetrieverThread::init(), RosMoveBaseThread::init(), fawkes::AspectManager::init(), LuaAgentPeriodicExecutionThread::init(), LuaAgentContinuousExecutionThread::init(), PlayerClientThread::init(), fawkes::ThreadList::init(), SkillerExecutionThread::init(), SickTiM55xCommonAcquisitionThread::init_device(), InterfaceGeneratorAmbiguousNameException::InterfaceGeneratorAmbiguousNameException(), InterfaceGeneratorInvalidAttributeException::InterfaceGeneratorInvalidAttributeException(), InterfaceGeneratorInvalidFlagException::InterfaceGeneratorInvalidFlagException(), InterfaceGeneratorInvalidTypeException::InterfaceGeneratorInvalidTypeException(), InterfaceGeneratorInvalidValueException::InterfaceGeneratorInvalidValueException(), InterfaceGeneratorMissingAttributeException::InterfaceGeneratorMissingAttributeException(), Visca::is_powered(), fawkes::KDLParserUnknownJointTypeException::KDLParserUnknownJointTypeException(), fawkes::SQLiteConfiguration::load(), fawkes::PluginManager::load(), CruizCoreXG1010AcquisitionThread::loop(), fawkes::ConfigNetworkHandler::loop(), fawkes::MissingArgumentException::MissingArgumentException(), fawkes::LoggerFactory::multilogger_instance(), fawkes::NetworkConfiguration::NetworkConfiguration(), firevision::SonyEviD100PControl::open(), fawkes::Module::open(), fawkes::OutOfBoundsException::OutOfBoundsException(), fawkes::PluginLoadException::PluginLoadException(), fawkes::PluginUnloadException::PluginUnloadException(), LaseEdlAcquisitionThread::pre_init(), fawkes::ThreadList::prepare_finalize(), firevision::FuseServerClientThread::process_getlutlist_message(), fawkes::BlackBoardInterfaceProxy::process_interface_message(), firevision::FuseServerClientThread::process_setlut_message(), firevision::ViscaControl::recv(), Visca::recv(), firevision::ViscaControl::recv_ack(), Visca::recv_ack(), FvBaseThread::register_for_camera(), BatteryMonitorTreeView::rem_host(), BBLogFile::repair_file(), Visca::reset_effect(), Visca::reset_pan_tilt(), Visca::reset_pan_tilt_limit(), Visca::reset_zoom(), firevision::ViscaControl::resetEffect(), firevision::ViscaControl::resetPanTilt(), firevision::ViscaControl::resetPanTiltLimit(), firevision::ViscaControl::resetZoom(), fawkes::AvahiThread::resolve_address(), fawkes::BroadcastDatagramSocket::send(), fawkes::MulticastDatagramSocket::send(), firevision::ViscaControl::send_nonblocking(), Visca::send_nonblocking(), firevision::ViscaControl::send_with_reply(), Visca::send_with_reply(), firevision::ViscaControl::set_address(), fawkes::ThreadManager::set_inifin(), Visca::set_mirror(), Visca::set_pan_tilt(), Visca::set_pan_tilt_limit(), firevision::FileLoader::set_pixel_height(), Visca::set_power(), Visca::set_zoom(), Visca::set_zoom_digital_enabled(), Visca::set_zoom_speed_tele(), Visca::set_zoom_speed_wide(), firevision::ViscaControl::setPanTilt(), firevision::ViscaControl::setPanTiltLimit(), firevision::ViscaControl::setZoom(), firevision::ViscaControl::setZoomDigitalEnabled(), firevision::ViscaControl::setZoomSpeedTele(), firevision::ViscaControl::setZoomSpeedWide(), fawkes::SharedMemory::SharedMemory(), firevision::SharedMemoryImageBuffer::SharedMemoryImageBuffer(), Visca::start_get_pan_tilt(), firevision::ViscaControl::startGetPanTilt(), fawkes::ThreadListSealedException::ThreadListSealedException(), fawkes::SQLiteConfiguration::transaction_rollback(), fawkes::UnableToOpenFileException::UnableToOpenFileException(), fawkes::UnknownArgumentException::UnknownArgumentException(), firevision::UnknownCameraControlTypeException::UnknownCameraControlTypeException(), firevision::UnknownCameraException::UnknownCameraException(), firevision::UnknownCameraTypeException::UnknownCameraTypeException(), fawkes::UnknownLoggerTypeException::UnknownLoggerTypeException(), fawkes::ThreadList::wakeup_unlocked(), firevision::JpegWriter::write(), fawkes::LuaInterfaceImporter::write(), firevision::Bumblebee2Camera::write_triclops_config_from_camera_to_file(), fawkes::BlackBoardInterfaceManager::~BlackBoardInterfaceManager(), and firevision::SharedMemoryCamera::~SharedMemoryCamera().

◆ append() [2/2]

void fawkes::Exception::append ( const Exception e)
throw (
)

Append message that are from another Exception.

Parameters
eException to copy messages from

Definition at line 376 of file exception.cpp.

References copy_messages().

◆ append_nolock()

void fawkes::Exception::append_nolock ( const char *  format,
  ... 
)
throw (
)
protected

Append messages without lock.

this can be used to append messages without locking the mutex if the mutex has been locked already to append many messages and keep their order intact and thus to prevent messages to be appended inbetween. Used for example in copy constructor.

Parameters
formatThe format of the primary message. Supports the same arguments as append(). The message is copied and not just referenced. Thus the memory has to be freed if it is a dynamic string on the heap.

Definition at line 392 of file exception.cpp.

References messages, messages_end, fawkes::Exception::message_list_t::msg, and fawkes::Exception::message_list_t::next.

Referenced by copy_messages(), and Exception().

◆ append_nolock_nocopy()

void fawkes::Exception::append_nolock_nocopy ( char *  msg)
throw (
)
protected

Append message without copying.

Can be used in subclasses to append messages that have been allocated on the heap. Use with extreme care. Do not add constant strings! This would cause your application to crash since the destructor will try to free all messages. The message list is not locked.

Parameters
msgMessage to append.

Definition at line 491 of file exception.cpp.

References messages, messages_end, fawkes::Exception::message_list_t::msg, and fawkes::Exception::message_list_t::next.

◆ append_nolock_va()

void fawkes::Exception::append_nolock_va ( const char *  format,
va_list  ap 
)
throw (
)
protected

Append messages without lock by formatted string.

this can be used to append messages without locking the mutex if the mutex has been locked already to append many messages and keep their order intact and thus to prevent messages to be appended inbetween. Used for example in copy constructor.

Parameters
formatformat of the message to be appended
apargument va_list for format

Definition at line 460 of file exception.cpp.

References messages, messages_end, fawkes::Exception::message_list_t::msg, and fawkes::Exception::message_list_t::next.

Referenced by append(), append_va(), fawkes::tf::ConnectivityException::ConnectivityException(), fawkes::tf::DisabledException::DisabledException(), Exception(), fawkes::tf::ExtrapolationException::ExtrapolationException(), fawkes::tf::InvalidArgumentException::InvalidArgumentException(), and fawkes::tf::LookupException::LookupException().

◆ append_va()

void fawkes::Exception::append_va ( const char *  format,
va_list  va 
)
throw (
)

Append messages to the message list.

Parameters
formatformat of the message to append, see printf(3) for details about formatting options.
vava_list with arguments matching the format

Definition at line 361 of file exception.cpp.

References append_nolock_va(), fawkes::Mutex::lock(), messages_mutex, and fawkes::Mutex::unlock().

Referenced by fawkes::AccessViolationException::AccessViolationException(), fawkes::CannotFinalizeThreadException::CannotFinalizeThreadException(), fawkes::CannotInitializeThreadException::CannotInitializeThreadException(), firevision::CaptureException::CaptureException(), fawkes::CouldNotOpenConfigException::CouldNotOpenConfigException(), fawkes::DestructionInProgressException::DestructionInProgressException(), fawkes::DivisionByZeroException::DivisionByZeroException(), fawkes::IllegalArgumentException::IllegalArgumentException(), InterfaceGeneratorInvalidContentException::InterfaceGeneratorInvalidContentException(), InterfaceGeneratorInvalidDocumentException::InterfaceGeneratorInvalidDocumentException(), fawkes::InterruptedException::InterruptedException(), fawkes::KatanaMotorCrashedException::KatanaMotorCrashedException(), fawkes::KatanaNoSolutionException::KatanaNoSolutionException(), fawkes::KatanaOutOfRangeException::KatanaOutOfRangeException(), fawkes::KatanaUnsupportedException::KatanaUnsupportedException(), fawkes::MissingParameterException::MissingParameterException(), fawkes::NonPointerTypeExpectedException::NonPointerTypeExpectedException(), fawkes::NotImplementedException::NotImplementedException(), fawkes::NotLockedException::NotLockedException(), fawkes::NullPointerException::NullPointerException(), fawkes::OutOfMemoryException::OutOfMemoryException(), fawkes::SocketException::SocketException(), fawkes::SyntaxErrorException::SyntaxErrorException(), fawkes::ThreadListNotSealedException::ThreadListNotSealedException(), fawkes::TimeoutException::TimeoutException(), fawkes::TypeMismatchException::TypeMismatchException(), and fawkes::UnknownTypeException::UnknownTypeException().

◆ begin()

Exception::iterator fawkes::Exception::begin ( )
throw (
)

Get iterator for messages.

Returns
iterator for messages

Definition at line 700 of file exception.cpp.

References messages.

Referenced by ClipsNavGraphThread::clips_context_destroyed(), LaserFilterThread::init(), fawkes::ConsoleLogger::log_debug(), fawkes::FileLogger::log_debug(), fawkes::SyslogLogger::log_debug(), fawkes::NetworkLogger::log_debug(), fawkes::SyslogLogger::log_error(), fawkes::ConsoleLogger::log_error(), fawkes::FileLogger::log_error(), fawkes::NetworkLogger::log_error(), fawkes::CacheLogger::log_error(), MongoLogLoggerThread::log_error(), fawkes::SyslogLogger::log_info(), fawkes::ConsoleLogger::log_info(), fawkes::FileLogger::log_info(), fawkes::NetworkLogger::log_info(), fawkes::SyslogLogger::log_warn(), fawkes::ConsoleLogger::log_warn(), fawkes::FileLogger::log_warn(), fawkes::NetworkLogger::log_warn(), MongoLogLoggerThread::loop(), NaoFawkesModule::NaoFawkesModule(), fawkes::ServiceSelectorCBE::on_btn_connect_clicked(), fawkes::ServiceSelectorCBE::on_service_selected(), WebviewPluginsRequestProcessor::process_request(), WebviewStaticRequestProcessor::process_request(), WebviewBlackBoardRequestProcessor::process_request(), WebviewTfRequestProcessor::process_request(), fawkes::ServiceChooserDialog::run_and_connect(), fawkes::InterfaceChooserDialog::run_and_open_for_reading(), fawkes::SyslogLogger::tlog_debug(), fawkes::ConsoleLogger::tlog_debug(), fawkes::FileLogger::tlog_debug(), fawkes::NetworkLogger::tlog_debug(), fawkes::SyslogLogger::tlog_error(), fawkes::ConsoleLogger::tlog_error(), fawkes::FileLogger::tlog_error(), fawkes::NetworkLogger::tlog_error(), fawkes::ConsoleLogger::tlog_info(), fawkes::SyslogLogger::tlog_info(), fawkes::FileLogger::tlog_info(), fawkes::NetworkLogger::tlog_info(), fawkes::ConsoleLogger::tlog_warn(), fawkes::SyslogLogger::tlog_warn(), fawkes::FileLogger::tlog_warn(), fawkes::NetworkLogger::tlog_warn(), fawkes::CacheLogger::unlock(), Bumblebee2CalibGtkWindow::~Bumblebee2CalibGtkWindow(), EclipseDebugger::~EclipseDebugger(), NaoGuiGtkWindow::~NaoGuiGtkWindow(), NetLogGuiGtkWindow::~NetLogGuiGtkWindow(), and SkillGuiGtkWindow::~SkillGuiGtkWindow().

◆ copy_messages()

void fawkes::Exception::copy_messages ( const Exception exc)
throw (
)
protected

Copy messages from given exception.

Copies the messages from exc to this exception.

Parameters
excException to copy messages from.

Definition at line 533 of file exception.cpp.

References append_nolock(), fawkes::Mutex::lock(), messages_iterator, messages_mutex, fawkes::Exception::message_list_t::msg, fawkes::Exception::message_list_t::next, and fawkes::Mutex::unlock().

Referenced by append(), Exception(), operator=(), and fawkes::PluginLoadException::PluginLoadException().

◆ end()

Exception::iterator fawkes::Exception::end ( )
throw (
)

Get end iterator for messages.

Returns
end iterator for messages.

Definition at line 717 of file exception.cpp.

References fawkes::Exception::iterator::iterator().

Referenced by fawkes::PluginLoader::load(), fawkes::ConsoleLogger::log_debug(), fawkes::FileLogger::log_debug(), fawkes::SyslogLogger::log_debug(), fawkes::NetworkLogger::log_debug(), fawkes::FileLogger::log_error(), fawkes::ConsoleLogger::log_error(), fawkes::SyslogLogger::log_error(), fawkes::NetworkLogger::log_error(), fawkes::CacheLogger::log_error(), MongoLogLoggerThread::log_error(), fawkes::FileLogger::log_info(), fawkes::SyslogLogger::log_info(), fawkes::ConsoleLogger::log_info(), fawkes::NetworkLogger::log_info(), fawkes::FileLogger::log_warn(), fawkes::ConsoleLogger::log_warn(), fawkes::SyslogLogger::log_warn(), fawkes::NetworkLogger::log_warn(), MongoLogLoggerThread::loop(), NaoFawkesModule::NaoFawkesModule(), WebviewPluginsRequestProcessor::process_request(), fawkes::SyslogLogger::tlog_debug(), fawkes::ConsoleLogger::tlog_debug(), fawkes::FileLogger::tlog_debug(), fawkes::NetworkLogger::tlog_debug(), fawkes::SyslogLogger::tlog_error(), fawkes::ConsoleLogger::tlog_error(), fawkes::FileLogger::tlog_error(), fawkes::NetworkLogger::tlog_error(), fawkes::ConsoleLogger::tlog_info(), fawkes::SyslogLogger::tlog_info(), fawkes::FileLogger::tlog_info(), fawkes::NetworkLogger::tlog_info(), fawkes::SyslogLogger::tlog_warn(), fawkes::ConsoleLogger::tlog_warn(), fawkes::FileLogger::tlog_warn(), fawkes::NetworkLogger::tlog_warn(), and fawkes::CacheLogger::unlock().

◆ generate_backtrace()

char * fawkes::Exception::generate_backtrace ( ) const
throw (
)

Generate backtrace string.

Returns
freshly allocated string of backtrace. Free after you are done.

Definition at line 586 of file exception.cpp.

◆ get_errno()

int fawkes::Exception::get_errno ( )
throw (
)

Get errno.

Returns
error number, may be 0 if not set

Definition at line 643 of file exception.cpp.

References _errno.

Referenced by SplRefBoxProcessor::refbox_process(), and fawkes::FawkesMainThread::~FawkesMainThread().

◆ operator=()

Exception & fawkes::Exception::operator= ( const Exception exc)
throw (
)

Assign an Exception.

As this is one of the Big Three (see C++ FAQ at http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.10) this is needed because we already need a copy constructor. Read about the copy constructor why this is the case.

See also
Exception(const Exception &exc)
Parameters
excThe exception with the values to assign to this exception.
Returns
reference to this object. Allows assignment chaining.

Definition at line 519 of file exception.cpp.

References copy_messages(), and messages_mutex.

◆ prepend()

void fawkes::Exception::prepend ( const char *  format,
  ... 
)
throw (
)

Prepend messages to the message list.

Parameters
formatformat of the message to prepend, see printf(3) for details about formatting options.

Definition at line 322 of file exception.cpp.

References fawkes::Mutex::lock(), messages_mutex, prepend_nolock_va(), and fawkes::Mutex::unlock().

Referenced by fawkes::abs_cfg_path(), StaticTransformsThread::finalize(), and fawkes::PluginManager::load().

◆ prepend_nolock_va()

void fawkes::Exception::prepend_nolock_va ( const char *  format,
va_list  ap 
)
throw (
)
protected

Prepend messages without lock by formatted string.

This can be used to append messages without locking the mutex if the mutex has been locked already to append many messages and keep their order intact and thus to prevent messages to be appended inbetween. Used for example in copy constructor.

Parameters
formatformat of the message to be appended
apargument va_list for format

Definition at line 429 of file exception.cpp.

References messages, messages_end, fawkes::Exception::message_list_t::msg, and fawkes::Exception::message_list_t::next.

Referenced by prepend().

◆ print_backtrace()

void fawkes::Exception::print_backtrace ( ) const
throw (
)

Prints a backtrace.

Definition at line 563 of file exception.cpp.

Referenced by PanTiltSonyEviD100PThread::init(), and what().

◆ print_trace()

void fawkes::Exception::print_trace ( )
throw (
)

Prints trace to stderr.

This prints out a message trace of all messages appended to the exception in chronological order starting with the oldest (first message appended via constructor or append(). Output will be sent to stderr.

Definition at line 619 of file exception.cpp.

References fawkes::Mutex::lock(), messages, messages_iterator, messages_mutex, fawkes::Exception::message_list_t::msg, fawkes::Exception::message_list_t::next, and fawkes::Mutex::unlock().

Referenced by BatteryMonitorTreeView::add_host(), JoystickBlackBoardLogger::bb_interface_data_changed(), JoystickBlackBoardActListener::bb_interface_message_received(), firevision::FuseClient::disconnect(), SkelGuiDepthDrawer::fill_texture(), FuseTransferWidget::fuse_inbound_received(), firevision::FuseImageListWidget::fuse_inbound_received(), FireVisionNetworkTool::fuse_inbound_received(), firevision::FuseImageListWidget::get_selected_image(), Firestation::get_window(), InterfaceParser::getFields(), InterfaceParser::getPseudoMaps(), FountainThread::init(), PanTiltSonyEviD100PThread::init(), fawkes::EclExternalBlackBoard::interfaces(), JoystickRemoteBlackBoardPoster::joystick_changed(), BlackBoardSynchronizationThread::loop(), SkillShellThread::loop(), fawkes::EclExternalRCSoftMapGraph::map_graph(), LaserDeadSpotCalibrator::num_detected_spots(), LaserGuiHildonWindow::on_connect(), InterfaceParser::parse(), DynamixelChain::ping(), RobotisRX28::ping(), fawkes::openni::HandIfObserver::process_queue(), fawkes::openni::SkelIfObserver::process_queue(), BatteryMonitorTreeView::rem_host(), ConfigChangeWatcherTool::run(), fawkes::PluginTreeView::set_gconf_prefix(), FuseTransferWidget::set_remote_lut_list_trv(), fawkes::InterruptibleBarrier::wait(), fawkes::LuaInterfaceImporter::write(), DynamixelChain::write_table_value(), RobotisRX28::write_table_value(), DynamixelChain::write_table_values(), RobotisRX28::write_table_values(), FuseViewerGtkWindow::~FuseViewerGtkWindow(), and NaoGuiGtkWindow::~NaoGuiGtkWindow().

◆ raise()

void fawkes::Exception::raise ( )
virtual

This can be used to throw this exception.

This can be used to throw this exception instance. This is a precaution if it is needed. See C++ FAQ 17.10.

Definition at line 555 of file exception.cpp.

◆ set_type_id()

void fawkes::Exception::set_type_id ( const char *  id)

Set exception type ID.

Set the type ID of this exception.

Parameters
idnew type ID, note that this must be a static string which is guaranteed to exist for the whole lifetime of the exception.
See also
Exception::type_id()

Definition at line 292 of file exception.cpp.

Referenced by BBLogFile::file_size(), BBLogFile::repair_file(), and BBLogFile::~BBLogFile().

◆ type_id()

const char * fawkes::Exception::type_id ( ) const

Get type ID.

Exceptions can have a type ID. This can be used to avoid having to declare numerous specific exception sub-classes to different errors, if it is essential to be able to differentiate them in the exception handling code. The type ID is a free-form string. It should NOT contain any message, rather it should be a one-word internal identifier that is never leaked to the user of the software, i.e. it is not printed anywhere. Note that the ID must be a static string, which exists for the whole life time of the exception, is generally not in a dynamically allocated memory (this very exception could indicate memory shortage). This also makes it thread-safe.

Returns
type ID

Definition at line 311 of file exception.cpp.

◆ what()

const char * fawkes::Exception::what ( ) const
throw (
)
virtual

Get primary string.

Messages are stored in a list. The first entry in this list is called primary message. This is why it is important to have a meaningful first message!

Returns
Returns a constant char pointer with the message. The message is private to the exception and may not be modified or freed (hence const) If no message has been set "Unknown error" is returned. This method may be overidden by other exceptions. This method is also called by the runtime system if the exception was not caught and resulted in a program termination.
string describing the general cause of the current error

Definition at line 661 of file exception.cpp.

References messages, fawkes::Exception::message_list_t::msg, and print_backtrace().

Referenced by RosJointThread::bb_interface_created(), RosPosition3DThread::bb_interface_created(), LaserPointCloudThread::bb_interface_created(), RosLaserScanThread::bb_interface_created(), RosTfThread::bb_interface_created(), RobotStatePublisherThread::bb_interface_created(), JoystickBlackBoardActListener::bb_interface_message_received(), LaserPointCloudThread::bb_interface_reader_removed(), fawkes::KatanaControllerKni::calibrate(), PanTiltRX28Thread::finalize(), DynamixelDriverThread::finalize(), KatanaActThread::finalize(), fawkes::KatanaControllerKni::get_angles(), fawkes::KatanaControllerKni::get_encoders(), firevision::ImageWidget::get_image_num(), fawkes::KatanaControllerKni::get_sensors(), fawkes::KatanaControllerKni::gripper_close(), fawkes::KatanaControllerKni::gripper_open(), HokuyoUrgAcquisitionThread::init(), OpenRaveMessageHandlerThread::init(), fawkes::KatanaControllerKni::init(), ColliThread::init(), KatanaActThread::init(), KatanaSensorAcquisitionThread::loop(), TfExampleThread::loop(), JacoInfoThread::loop(), ROSWebviewThread::loop(), NavGraphClustersThread::loop(), NavGraphThread::loop(), KatanaActThread::loop(), fawkes::KatanaControllerKni::move_motor_by(), fawkes::KatanaControllerKni::move_motor_to(), fawkes::KatanaControllerKni::move_to(), KatanaCalibrationThread::once(), KatanaMotorControlThread::once(), KatanaGotoThread::once(), KatanaGripperThread::once(), KatanaActThread::once(), LaserGuiGtkWindow::open_interfaces(), RRDWebRequestProcessor::process_request(), WebviewBlackBoardRequestProcessor::process_request(), fawkes::KatanaControllerKni::read_coordinates(), fawkes::KatanaControllerKni::read_motor_data(), fawkes::KatanaControllerKni::read_sensor_data(), PTUJoystickControl::run(), fawkes::KatanaControllerKni::set_max_velocity(), firevision::ImageWidget::show(), JacoGotoThread::stop(), fawkes::KatanaControllerKni::stop(), fawkes::KatanaControllerKni::turn_off(), fawkes::KatanaControllerKni::turn_on(), KatanaActThread::update_sensor_values(), fawkes::BlackBoardInterfaceListMaintainer::~BlackBoardInterfaceListMaintainer(), and SkillGuiGtkWindow::~SkillGuiGtkWindow().

◆ what_no_backtrace()

const char * fawkes::Exception::what_no_backtrace ( ) const
throw (
)
virtual

Get primary string (does not implicitly print the back trace).

Messages are stored in a list. The first entry in this list is called primary message. This is why it is important to have a meaningful first message!

Returns
Returns a constant char pointer with the message. The message is private to the exception and may not be modified or freed (hence const) If no message has been set "Unknown error" is returned. This method may be overidden by other exceptions. This method is also called by the runtime system if the exception was not caught and resulted in a program termination.
string describing the general cause of the current error

Definition at line 686 of file exception.cpp.

References messages, and fawkes::Exception::message_list_t::msg.

Referenced by ClipsTFThread::clips_context_destroyed(), fawkes::NavGraph::cost(), fawkes::OpenPRSKernelManager::create_kernel(), protobuf_clips::ClipsProtobufCommunicator::disable_server(), JacoBimanualActThread::finalize(), JacoActThread::finalize(), JoystickTeleOpThread::finalize(), AmclThread::finalize(), fawkes::EclExternalBlackBoard::interfaces(), JacoBimanualOpenraveThread::JacoBimanualOpenraveThread(), JacoOpenraveThread::JacoOpenraveThread(), JacoGotoThread::loop(), DirectRobotinoComThread::loop(), NavGraphClustersThread::loop(), NavGraphThread::loop(), ColliThread::loop(), JacoBimanualGotoThread::move_gripper(), JacoOpenraveThread::set_target_ang(), fawkes::OpenPRSComm::transmit_command_f(), fawkes::BlackBoardInterfaceListMaintainer::~BlackBoardInterfaceListMaintainer(), and fawkes::OpenPRSMessagePasserProxy::~OpenPRSMessagePasserProxy().

Member Data Documentation

◆ _errno

fawkes::Exception::_errno
protected

Error number, should be used if the error was caused by a method that supplies errno.

Definition at line 111 of file exception.h.

Referenced by Exception(), and get_errno().

◆ messages

fawkes::Exception::messages
protected

List of messages.

Should not be NULL. Messages are append with append(). Using a custom list to avoid including STL stuff in this core file.

See also
append()

Definition at line 106 of file exception.h.

Referenced by append_nolock(), append_nolock_nocopy(), append_nolock_va(), begin(), Exception(), prepend_nolock_va(), print_trace(), what(), what_no_backtrace(), and ~Exception().

◆ messages_end

fawkes::Exception::messages_end
protected

Pointer that points to the very last message.

Used for fast appending.

Definition at line 108 of file exception.h.

Referenced by append_nolock(), append_nolock_nocopy(), append_nolock_va(), Exception(), prepend_nolock_va(), and ~Exception().

◆ messages_iterator

fawkes::Exception::messages_iterator
protected

Iterator to iterate over messages.

Definition at line 107 of file exception.h.

Referenced by copy_messages(), Exception(), print_trace(), and ~Exception().

◆ messages_mutex

fawkes::Exception::messages_mutex
protected

Mutex to protect operations on messages list.

Definition at line 109 of file exception.h.

Referenced by append(), append_va(), copy_messages(), Exception(), operator=(), prepend(), print_trace(), and ~Exception().


The documentation for this class was generated from the following files: