JUCE: Result Class Reference

JUCE

Public Member Functions | Static Public Member Functions | List of all members
Result Class Reference
juce_core » misc

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>`

## Public Member Functions
bool | wasOk () const noexcept
| Returns true if this result indicates a success. More...
bool | failed () const noexcept
| Returns true if this result indicates a failure. 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...
const String & | getErrorMessage () const noexcept
| Returns the error message that was set when this result was created. More...
| Result (const Result &)
Result & | operator= (const Result &)
| Result (Result &&) noexcept
Result & | operator= (Result &&) noexcept
bool | operator== (const Result &other) const noexcept
bool | operator!= (const Result &other) const noexcept

## Static Public Member Functions
static Result | ok () noexcept
| Creates and returns a 'successful' result. More...
static Result | fail (const String &errorMessage) noexcept
| Creates a 'failure' result. More...

## 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());
}
Result
Represents the 'success' or 'failure' of an operation, and holds an associated error message to descr...
Definition: juce_Result.h:58
Result::fail
static Result fail(const String &errorMessage) noexcept
Creates a 'failure' result.
Result::ok
static Result ok() noexcept
Creates and returns a 'successful' result.
Definition: juce_Result.h:62
gl::result
GLuint64EXT * result
Definition: juce_gl.h:10113

## Constructor & Destructor Documentation

## ◆ Result() [1/2]

Result::Result | ( | const Result & |  | ) |

## ◆ Result() [2/2]

Result::Result | ( | Result && |  | ) |
| noexcept

## Member Function Documentation

## ◆ ok()

static Result Result::ok | ( |  | ) |
| staticnoexcept

Creates and returns a 'successful' result.

## ◆ fail()

static Result 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.

## ◆ wasOk()

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

Returns true if this result indicates a success.

## ◆ failed()

bool 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.

## ◆ operator bool()

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

Returns true if this result indicates a success.

This is equivalent to calling wasOk().

## ◆ operator!()

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

Returns true if this result indicates a failure.

This is equivalent to calling failed().

## ◆ getErrorMessage()

const String & 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;

## ◆ operator=() [1/2]

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

## ◆ operator=() [2/2]

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

## ◆ operator==()

bool Result::operator== | ( | const Result & | other | ) | const
| noexcept

## ◆ operator!=()

bool Result::operator!= | ( | const Result & | other | ) | const
| noexcept

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

- juce_Result.h