#include <msp/io/print.h>
#include <msp/strings/utils.h>
#include "application.h"
+#include "except.h"
#include "getopt.h"
using namespace std;
Application::Application(const string &n)
{
if(_app)
- throw logic_error("instance already exists");
+ throw already_called("Application::Application");
if(!n.empty())
_name = n;
void Application::set_startup_info(const char *argv0, void *data)
{
if(_argv0)
- throw logic_error("startup info already set");
+ throw already_called("Application::set_startup_info");
static FS::Path exe;
Application::Starter::Starter()
{
if(_starter)
- throw logic_error("Can't create more than one Starter instance");
+ throw already_called("Application::Starter::Starter");
_starter = this;
}
--- /dev/null
+#ifndef MSP_CORE_EXCEPT_H_
+#define MSP_CORE_EXCEPT_H_
+
+#include <stdexcept>
+
+namespace Msp {
+
+class invalid_state: public std::logic_error
+{
+public:
+ invalid_state(const std::string &w): logic_error(w) { }
+};
+
+
+class already_called: public invalid_state
+{
+public:
+ already_called(const std::string &w): invalid_state(w) { }
+};
+
+
+class unsupported: public std::logic_error
+{
+public:
+ unsupported(const std::string &w): logic_error(w) { }
+};
+
+
+class internal_error: public std::logic_error
+{
+public:
+ internal_error(const std::string &w): logic_error(w) { }
+};
+
+} // namespace Msp;
+
+#endif
#include <msp/io/console.h>
+#include "except.h"
#include "process.h"
#include "process_private.h"
unsigned Process::get_exit_code() const
{
if(!finished)
- throw logic_error("not finished");
+ throw invalid_state("not finished");
return exit_code;
}
-#include <stdexcept>
+#include "except.h"
#include "thread.h"
#include "thread_private.h"
void Thread::launch()
{
if(_state>=RUNNING)
- throw logic_error("already launched");
+ throw already_called("Thread::launch");
platform_launch();
_state = RUNNING;
#include <msp/core/systemerror.h>
#include <msp/fs/dir.h>
#include <msp/io/console.h>
+#include "except.h"
#include "process.h"
#include "process_private.h"
bool Process::wait(bool block)
{
if(!running)
- throw logic_error("not running");
+ throw invalid_state("not running");
int status;
int pid = waitpid(priv->info.pid, &status, (block ? 0 : WNOHANG));
#include <msp/core/systemerror.h>
#include <msp/io/handle_private.h>
#include <msp/strings/utils.h>
+#include "except.h"
#include "process.h"
#include "process_private.h"
bool Process::wait(bool block)
{
if(!running)
- throw logic_error("not running");
+ throw invalid_state("not running");
DWORD ret = WaitForSingleObject(priv->info.hProcess, (block ? INFINITE : 0));
if(ret==WAIT_FAILED)
#include <msp/core/application.h>
#include <msp/core/environ.h>
+#include <msp/core/except.h>
#include <msp/strings/utils.h>
#include "dir.h"
#include "path.h"
{
const char *argv0 = Application::get_argv0();
if(!argv0)
- throw logic_error("no startup command");
+ throw invalid_state("no startup command");
Path dir = get_bin_dir(argv0);
{
const char *argv0 = Application::get_argv0();
if(!argv0)
- throw logic_error("no startup command");
+ throw invalid_state("no startup command");
Path dir = get_bin_dir(argv0);
{
const char *argv0 = Application::get_argv0();
if(!argv0)
- throw logic_error("no startup command");
+ throw invalid_state("no startup command");
Path dir = get_bin_dir(argv0);
#include <msp/core/algorithm.h>
+#include <msp/core/except.h>
#include "filemonitor.h"
#include "filemonitor_platform.h"
void FileMonitor::use_event_dispatcher(IO::EventDispatcher &ed)
{
if(event_disp)
- throw logic_error("event_disp!=nullptr");
+ throw already_called("FileMonitor::use_event_dispatcher");
event_disp = &ed;
platform_use_event_dispatcher();
#include <msp/core/application.h>
#include <msp/core/environ.h>
+#include <msp/core/except.h>
#include "dir.h"
using namespace std;
{
const string &appname = Application::get_name();
if(appname.empty())
- throw logic_error("no application name");
+ throw invalid_state("no application name");
char buf[1024];
unsigned len = get_application_support_dir(buf, sizeof(buf));
#include <msp/core/application.h>
#include <msp/core/environ.h>
+#include <msp/core/except.h>
#include "dir.h"
using namespace std;
{
const string &appname = Application::get_name();
if(appname.empty())
- throw logic_error("no application name");
+ throw invalid_state("no application name");
return get_home_dir()/("."+appname);
}
#include <shlobj.h>
#include <msp/core/application.h>
+#include <msp/core/except.h>
#include "dir.h"
using namespace std;
{
const string &appname = Application::get_name();
if(appname.empty())
- throw logic_error("no application name");
+ throw invalid_state("no application name");
char datadir[MAX_PATH];
if(SHGetFolderPath(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, datadir)==S_OK)
FileMonitor::Private::Private(FileMonitor &)
{
- throw logic_error("not implemented");
+ throw unsupported("FileMonitor");
}
} // namespace FS
Path readlink(const Path &link)
{
(void)link;
- throw logic_error("no symbolic links on win32");
+ throw unsupported("no symbolic links on win32");
}
Path realpath(const Path &path)
+#include <msp/core/except.h>
#include "asset.h"
using namespace std;
void Asset::set_block(bool)
{
- throw logic_error("Asset::set_block");
+ throw unsupported("Asset::set_block");
}
void Asset::set_inherit(bool)
{
- throw logic_error("Asset::set_inherit");
+ throw unsupported("Asset::set_inherit");
}
size_t Asset::do_write(const char *, size_t)
const Handle &Asset::get_handle(Mode)
{
- throw logic_error("Asset::get_handle");
+ throw unsupported("Asset::get_handle");
}
} // namespace IO
#include <cstring>
-#include <stdexcept>
+#include <msp/core/except.h>
#include "buffered.h"
#include "handle.h"
void Buffered::set_block(bool)
{
- throw logic_error("Buffered::set_block");
+ throw unsupported("Buffered::set_block");
}
void Buffered::set_inherit(bool)
{
- throw logic_error("Buffered::set_block");
+ throw unsupported("Buffered::set_block");
}
void Buffered::flush()
const Handle &Buffered::get_handle(Mode)
{
- throw logic_error("Buffered::get_handle");
+ throw unsupported("Buffered::get_handle");
}
void Buffered::set_op(Mode op)
+#include <msp/core/except.h>
#include "file.h"
#include "handle_private.h"
void BufferedFile::set_inherit(bool)
{
- throw logic_error("BufferedFile::set_inherit");
+ throw unsupported("BufferedFile::set_inherit");
}
size_t BufferedFile::do_write(const char *buf, size_t size)
const Handle &BufferedFile::get_handle(Mode)
{
- throw logic_error("BufferedFile::get_handle");
+ throw unsupported("BufferedFile::get_handle");
}
SeekOffset BufferedFile::seek(SeekOffset offset, SeekType type)
#include <algorithm>
#include <cstring>
+#include <msp/core/except.h>
#include "handle.h"
#include "memory.h"
void Memory::set_block(bool)
{
- throw logic_error("Memory::set_block");
+ throw unsupported("Memory::set_block");
}
void Memory::set_inherit(bool)
{
- throw logic_error("Memory::set_inherit");
+ throw unsupported("Memory::set_inherit");
}
size_t Memory::do_write(const char *buf, size_t size)
const Handle &Memory::get_handle(Mode)
{
- throw logic_error("Memory::get_handle");
+ throw unsupported("Memory::get_handle");
}
SeekOffset Memory::seek(SeekOffset off, SeekType type)
#ifdef _WIN32
if(objects.size()>=MAXIMUM_WAIT_OBJECTS)
- throw logic_error("Maximum number of wait objects reached");
+ throw invalid_state("Maximum number of wait objects reached");
#endif
objects.push_back(PolledObject(&obj, ev));
-#include <stdexcept>
+#include <msp/core/except.h>
#include "slice.h"
using namespace std;
void Slice::set_block(bool)
{
- throw logic_error("Slice::set_block");
+ throw unsupported("Slice::set_block");
}
void Slice::set_inherit(bool)
{
- throw logic_error("Slice::set_inherit");
+ throw unsupported("Slice::set_inherit");
}
void Slice::flush()
const Handle &Slice::get_handle(Mode)
{
- throw logic_error("Slice::get_handle");
+ throw unsupported("Slice::get_handle");
}
SeekOffset Slice::seek(SeekOffset off, SeekType type)
case Msp::IO::Console::CIN: return STD_INPUT_HANDLE;
case Msp::IO::Console::COUT: return STD_OUTPUT_HANDLE;
case Msp::IO::Console::CERR: return STD_ERROR_HANDLE;
- default: throw invalid_argument("stream_to_sys");
+ default: throw internal_error("stream_to_sys");
}
}
#ifdef WITH_ZLIB
#include <zlib.h>
#endif
+#include <msp/core/except.h>
#include "zlibcompressed.h"
using namespace std;
(void)buffer_size;
(void)stream_end;
(void)level;
- throw zlib_error("unsupported", -1);
+ throw unsupported("ZlibCompressed");
#endif
}
void ZlibCompressed::set_block(bool)
{
- throw logic_error("ZlibCompressed::set_block");
+ throw unsupported("ZlibCompressed::set_block");
}
void ZlibCompressed::set_inherit(bool)
{
- throw logic_error("ZlibCompressed::set_inherit");
+ throw unsupported("ZlibCompressed::set_inherit");
}
void ZlibCompressed::flush()
const Handle &ZlibCompressed::get_handle(Mode)
{
- throw logic_error("ZlibCompressed::get_handle");
+ throw unsupported("ZlibCompressed::get_handle");
}
} // namespace IO
+#include <msp/core/except.h>
#include "ascii.h"
#include "iso2022jp.h"
#include "jisx0201.h"
else if(dec)
return dec->decode_char(str, i);
else
- throw logic_error("no sub-decoder");
+ throw internal_error("no sub-decoder");
if(result>=0)
return result;
#include <list>
#include <stack>
#include <vector>
+#include <msp/core/except.h>
#include "format.h"
#include "regex.h"
input_consumed = true;
}
else
- throw logic_error("invalid instruction in regex bytecode");
+ throw internal_error("invalid instruction in regex bytecode");
if(match_result==negate_match)
terminate = true;