2011-05-23 17:18:52 +10:00
|
|
|
/*
|
2015-04-13 18:05:28 +10:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-05-23 17:18:52 +10:00
|
|
|
*
|
2015-04-13 18:05:28 +10:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-05-23 17:18:52 +10:00
|
|
|
*
|
2015-04-13 18:05:28 +10:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2011-05-23 17:18:52 +10:00
|
|
|
*
|
2012-04-23 13:06:41 +10:00
|
|
|
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
|
2011-05-23 17:18:52 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __EXCEPT_HPP
|
|
|
|
#define __EXCEPT_HPP
|
|
|
|
|
2012-05-08 15:01:56 +10:00
|
|
|
#include "platform.hpp"
|
|
|
|
|
2011-05-23 17:18:52 +10:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2012-05-16 15:01:01 +10:00
|
|
|
namespace util {
|
|
|
|
class input_error : public std::runtime_error {
|
|
|
|
public:
|
2017-05-23 12:50:51 +10:00
|
|
|
explicit input_error (const std::string &_what):
|
2012-05-16 15:01:21 +10:00
|
|
|
runtime_error (_what)
|
|
|
|
{ ; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class output_error : public std::runtime_error {
|
|
|
|
public:
|
2017-05-23 12:50:51 +10:00
|
|
|
explicit output_error (const std::string &_what):
|
2011-05-23 17:18:52 +10:00
|
|
|
runtime_error (_what)
|
2012-05-16 15:01:01 +10:00
|
|
|
{ ; }
|
|
|
|
};
|
2011-05-23 17:18:52 +10:00
|
|
|
|
|
|
|
|
2012-05-16 15:01:01 +10:00
|
|
|
class unavailable_error : public std::runtime_error {
|
|
|
|
public:
|
2017-05-23 12:50:51 +10:00
|
|
|
explicit unavailable_error (const std::string &_what):
|
2012-05-16 15:01:01 +10:00
|
|
|
runtime_error (_what)
|
|
|
|
{ ; }
|
|
|
|
};
|
2011-05-23 17:18:52 +10:00
|
|
|
|
|
|
|
|
2012-05-16 15:01:01 +10:00
|
|
|
/// An exception class used for reporting errors signalled by errno.
|
|
|
|
class errno_error : public std::runtime_error {
|
2016-04-27 16:06:32 +10:00
|
|
|
public:
|
2017-05-23 12:50:51 +10:00
|
|
|
explicit errno_error (int code);
|
2016-04-27 16:06:32 +10:00
|
|
|
errno_error ();
|
2011-05-25 23:02:15 +10:00
|
|
|
|
2016-04-27 16:06:58 +10:00
|
|
|
int code (void) const;
|
|
|
|
static int last_code (void);
|
|
|
|
|
2016-04-27 16:06:32 +10:00
|
|
|
static void try_code (void);
|
|
|
|
static void try_code (int code);
|
2012-04-30 11:50:53 +10:00
|
|
|
|
2016-04-27 16:06:32 +10:00
|
|
|
static void throw_code [[gnu::noreturn]] (void);
|
|
|
|
static void throw_code [[gnu::noreturn]] (int code);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_code;
|
2012-05-16 15:01:01 +10:00
|
|
|
};
|
2012-05-17 14:16:09 +10:00
|
|
|
}
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-05-08 15:01:56 +10:00
|
|
|
#if defined(PLATFORM_WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
|
2012-05-17 14:16:09 +10:00
|
|
|
namespace util {
|
2012-05-16 15:01:01 +10:00
|
|
|
class win32_error : public std::runtime_error {
|
2016-04-27 16:07:42 +10:00
|
|
|
public:
|
2017-05-23 12:50:51 +10:00
|
|
|
explicit win32_error (DWORD _code);
|
2016-04-27 16:07:42 +10:00
|
|
|
win32_error ();
|
|
|
|
|
|
|
|
DWORD code (void) const;
|
|
|
|
static DWORD last_code (void);
|
2012-05-08 15:01:56 +10:00
|
|
|
|
2016-04-27 16:07:42 +10:00
|
|
|
static void try_code (void);
|
|
|
|
static void try_code (DWORD);
|
2012-05-08 15:01:56 +10:00
|
|
|
|
2016-04-27 16:07:42 +10:00
|
|
|
static void throw_code [[gnu::noreturn]] (void);
|
|
|
|
static void throw_code [[gnu::noreturn]] (DWORD);
|
2015-08-10 15:42:58 +10:00
|
|
|
|
2016-04-27 16:07:42 +10:00
|
|
|
static std::string code_string (void);
|
|
|
|
static std::string code_string (DWORD);
|
2016-04-05 11:04:50 +10:00
|
|
|
|
2016-04-27 16:07:42 +10:00
|
|
|
private:
|
|
|
|
DWORD m_code;
|
2012-05-16 15:01:01 +10:00
|
|
|
};
|
|
|
|
}
|
2012-05-17 14:16:09 +10:00
|
|
|
#endif
|
2012-05-08 15:01:56 +10:00
|
|
|
|
2015-04-13 18:06:08 +10:00
|
|
|
#endif
|