Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 873 Bytes

result.md

File metadata and controls

57 lines (42 loc) · 873 Bytes

Result

  • Headers : Win32Ex/Result.hpp

Contents

Reference

Classes

Result<T>

Result<T &>

Example

#include <Win32Ex/Result.hpp>

using namespace Win32Ex;

Result<int> GetValue(bool error)
{
    if (error)
        return Error(ERROR_INVALID_PARAMETER, "Invalid parameter");
    return 1;
}

...

int value = 0;
try
{
    value = GetValue(true).Get();
}
catch (const Error &e)
{
    e.ErrorCode; // == ERROR_INVALID_PARAMETER
    e.what();      // == "Invalid parameter"
}
catch (const std::exception &e)
{
    e.what(); // == "Invalid parameter"
}
value = GetValue(true).Get(-1); // == -1
value = GetValue(false).Get(); // == 1