JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::Result Class Reference

Represents the 'success' or 'failure' of an operation, and holds an associated error message to describe the error when there's a failure. More...

#include <juce_Result.h>

Collaboration diagram for juce::Result:

Public Member Functions

 Result (const Result &)
 
 Result (Result &&) noexcept
 
bool failed () const noexcept
 Returns true if this result indicates a failure. More...
 
const StringgetErrorMessage () const noexcept
 Returns the error message that was set when this result was created. More...
 
 operator bool () const noexcept
 Returns true if this result indicates a success. More...
 
bool operator! () const noexcept
 Returns true if this result indicates a failure. More...
 
bool operator!= (const Result &other) const noexcept
 
Resultoperator= (const Result &)
 
Resultoperator= (Result &&) noexcept
 
bool operator== (const Result &other) const noexcept
 
bool wasOk () const noexcept
 Returns true if this result indicates a success. More...
 

Static Public Member Functions

static Result fail (const String &errorMessage) noexcept
 Creates a 'failure' result. More...
 
static Result ok () noexcept
 Creates and returns a 'successful' result. More...
 

Private Member Functions

 Result () noexcept
 
 Result (const String &) noexcept
 
 operator int () const
 
 operator void * () const
 

Private Attributes

String errorMessage
 

Detailed Description

Represents the 'success' or 'failure' of an operation, and holds an associated error message to describe the error when there's a failure.

E.g.

Result myOperation()
{
if (doSomeKindOfFoobar())
return Result::ok();
else
return Result::fail ("foobar didn't work!");
}
const Result result (myOperation());
if (result.wasOk())
{
...it's all good...
}
else
{
warnUserAboutFailure ("The foobar operation failed! Error message was: "
+ result.getErrorMessage());
}

{Core}

Constructor & Destructor Documentation

◆ Result() [1/4]

juce::Result::Result ( const Result )

◆ Result() [2/4]

juce::Result::Result ( Result &&  )
noexcept

◆ Result() [3/4]

juce::Result::Result ( )
privatenoexcept

◆ Result() [4/4]

juce::Result::Result ( const String )
explicitprivatenoexcept

Member Function Documentation

◆ fail()

static Result juce::Result::fail ( const String errorMessage)
staticnoexcept

Creates a 'failure' result.

If you pass a blank error message in here, a default "Unknown Error" message will be used instead.

Referenced by juce::anonymous_namespace{juce_posix_SharedCode.h}::getResultForErrno().

◆ failed()

bool juce::Result::failed ( ) const
noexcept

Returns true if this result indicates a failure.

You can use getErrorMessage() to retrieve the error message associated with the failure.

◆ getErrorMessage()

const String& juce::Result::getErrorMessage ( ) const
noexcept

Returns the error message that was set when this result was created.

For a successful result, this will be an empty string;

◆ ok()

static Result juce::Result::ok ( )
inlinestaticnoexcept

Creates and returns a 'successful' result.

References juce::operator!=(), and juce::operator==().

Referenced by juce::anonymous_namespace{juce_posix_SharedCode.h}::getResultForReturnValue().

◆ operator bool()

juce::Result::operator bool ( ) const
noexcept

Returns true if this result indicates a success.

This is equivalent to calling wasOk().

◆ operator int()

juce::Result::operator int ( ) const
private

◆ operator void *()

juce::Result::operator void * ( ) const
private

◆ operator!()

bool juce::Result::operator! ( ) const
noexcept

Returns true if this result indicates a failure.

This is equivalent to calling failed().

◆ operator!=()

bool juce::Result::operator!= ( const Result other) const
noexcept

◆ operator=() [1/2]

Result& juce::Result::operator= ( const Result )

◆ operator=() [2/2]

Result& juce::Result::operator= ( Result &&  )
noexcept

◆ operator==()

bool juce::Result::operator== ( const Result other) const
noexcept

◆ wasOk()

bool juce::Result::wasOk ( ) const
noexcept

Returns true if this result indicates a success.

Member Data Documentation

◆ errorMessage

String juce::Result::errorMessage
private

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