JX Application Framework
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
JError Class Reference

#include <JError.h>

Inheritance diagram for JError:
[legend]

Public Member Functions

 JError (const JError &source)
 
JErroroperator= (const JError &source)
 
const JStringGetMessage () const
 
void ReportIfError () const
 
bool OK () const
 
- Public Member Functions inherited from JRTTIBase
virtual ~JRTTIBase ()
 
bool Is (const JUtf8Byte *type) const
 
const JUtf8ByteGetType () const
 

Protected Member Functions

 JError (const JUtf8Byte *type, const JUtf8Byte *msg=nullptr)
 
void SetMessage (const JString &msg)
 
void SetMessage (const JUtf8Byte *map[], const JSize size)
 
- Protected Member Functions inherited from JBroadcaster::Message
 JRTTIBase (const JUtf8Byte *type)
 
- Protected Member Functions inherited from JRTTIBase
 JRTTIBase (const JUtf8Byte *type)
 

Detailed Description

This class is the base class of all errors returned by JCore functions.
Every class or utility function defines whatever special error classes
it needs and then returns type JError.

    Note that derived classes cannot store -any- extra information.
    Consider the following code:

    JError foo()
    {
        return JUnknownError();
    }

    If this looks scary to you, you understand C++.  If you understand
    why this compiles, you grok C++.  What happens is that an object of
    type JUnknownError is created and then the JError copy constructor
    is called to construct a JError object from the JUnknownError object.
    This new JError object is returned and the JUnknownError object is
    deleted.  (Just another reason why most JCore objects don't have
    copy constructors.)

Since every JError message stores a descriptive message, one often only
needs to check if the return value is kJNoError.  If it isn't, then pass
the object's long message to JStringManager::ReportError() or
JUserNotification::ReportError().

Since the type must be unique for every JError, the descriptive message
can be stored in JStringManager.  This is automatic when the message
passed to the constructor is nullptr.

Refer to the documentation for JRTTIBase for the recommended way to
define type strings.

Constructor & Destructor Documentation

◆ JError() [1/2]

JError::JError ( const JError source)

◆ JError() [2/2]

JError::JError ( const JUtf8Byte type,
const JUtf8Byte msg = nullptr 
)
protected

If msg == nullptr, it is retrieved from JStringManager.

If copyMsg == true, we make a copy of the data in msg. Otherwise, we just store the pointer that is passed in.

Member Function Documentation

◆ GetMessage()

const JString & JError::GetMessage ( ) const
inline

◆ OK()

bool JError::OK ( ) const
inline

◆ operator=()

JError & JError::operator= ( const JError source)

◆ ReportIfError()

void JError::ReportIfError ( ) const

◆ SetMessage() [1/2]

void JError::SetMessage ( const JString msg)
protected

This is provided so derived classes can construct their message dynamically, something that cannot be done safely in the initializer list.

◆ SetMessage() [2/2]

void JError::SetMessage ( const JUtf8Byte map[],
const JSize  size 
)
protected

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