libcruft-util/except.hpp

98 lines
2.4 KiB
C++
Raw Normal View History

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>
namespace util {
class input_error : public std::runtime_error {
public:
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:
output_error (const std::string &_what):
2011-05-23 17:18:52 +10:00
runtime_error (_what)
{ ; }
};
2011-05-23 17:18:52 +10:00
class unavailable_error : public std::runtime_error {
public:
unavailable_error (const std::string &_what):
runtime_error (_what)
{ ; }
};
2011-05-23 17:18:52 +10:00
/// An exception class used for reporting errors signalled by errno.
class errno_error : public std::runtime_error {
public:
errno_error (int code);
errno_error ();
int code (void) const;
static int last_code (void);
static void try_code (void);
static void try_code (int code);
2012-04-30 11:50:53 +10:00
static void throw_code [[gnu::noreturn]] (void);
static void throw_code [[gnu::noreturn]] (int code);
private:
int m_code;
};
}
2011-05-23 17:18:52 +10:00
2012-05-08 15:01:56 +10:00
#if defined(PLATFORM_WIN32)
#include <windows.h>
namespace util {
class win32_error : public std::runtime_error {
public:
win32_error (DWORD _code);
win32_error ();
DWORD code (void) const;
static DWORD last_code (void);
2012-05-08 15:01:56 +10:00
static void try_code (void);
static void try_code (DWORD);
2012-05-08 15:01:56 +10:00
static void throw_code [[gnu::noreturn]] (void);
static void throw_code [[gnu::noreturn]] (DWORD);
2015-08-10 15:42:58 +10:00
static std::string code_string (void);
static std::string code_string (DWORD);
2016-04-05 11:04:50 +10:00
private:
DWORD m_code;
};
}
#endif
2012-05-08 15:01:56 +10:00
2015-04-13 18:06:08 +10:00
#endif