本文整理汇总了C++中SystemException函数的典型用法代码示例。如果您正苦于以下问题:C++ SystemException函数的具体用法?C++ SystemException怎么用?C++ SystemException使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SystemException函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
std::string EnvironmentImpl::osNameImpl()
{
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
switch (vi.dwPlatformId)
{
case VER_PLATFORM_WIN32s:
return "Windows 3.x";
case VER_PLATFORM_WIN32_WINDOWS:
return vi.dwMinorVersion == 0 ? "Windows 95" : "Windows 98";
case VER_PLATFORM_WIN32_NT:
return "Windows NT";
default:
return "Unknown";
}
}
示例2: sizeof
std::string EnvironmentImpl::osDisplayNameImpl()
{
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
switch(vi.dwMajorVersion)
{
case 6:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows Vista/Server 2008";
case 1:
return "Windows 7/Server 2008 SP2";
default:
return "Unknown";
}
case 5:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows 2000";
case 1:
return "Windows XP";
case 2:
return "Windows Server 2003/Windows Server 2003 R2";
default:
return "Unknown";
}
case 4:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows 95/Windows NT 4.0";
case 10:
return "Windows 98";
case 90:
return "Windows ME";
default:
return "Unknown";
}
default:
return "Unknown";
}
}
示例3: UserException
/**
* \brief Function to make a link from a given
* \param src : the source file
* \return the path of the link
* Throw exception on error
*/
std::string
vishnu::mklink(const std::string& src) {
if( ! bfs::exists(src) ) {
throw UserException(ERRCODE_FILENOTFOUND, "SSHJobExec::mklink : "
"the file "+ src + " doesnot exist.");
}
bfs::path dest ;
try {
dest = bfs::unique_path("/tmp/vishnulink%%%%%%") ;
bfs::create_symlink(src, dest) ;
}catch (...) {
throw SystemException(ERRCODE_SYSTEM, "SSHJobExec::mklink : "
"error while making a link on the file " + src + " from " + dest.string());
}
return dest.string() ;
}
示例4: switch
void RWLockImpl::readLockImpl()
{
HANDLE h[2];
h[0] = _mutex;
h[1] = _readEvent;
switch (WaitForMultipleObjects(2, h, TRUE, INFINITE))
{
case WAIT_OBJECT_0:
case WAIT_OBJECT_0 + 1:
++_readers;
ResetEvent(_writeEvent);
ReleaseMutex(_mutex);
poco_assert_dbg(_writers == 0);
break;
default:
throw SystemException("cannot lock reader/writer lock");
}
}
示例5: throw
/**
* Create a random access stream from a file, removing it if it already exists.
* @param path Path of the file to open.
* @param access Type of access (one of READ, WRITE, READ_WRITE).
* @return Opened file.
* @throws IOException Thrown if there is an error.
*/
io::RandomAccessStream *System::createRandomFile(
const sys::Path& path,
access_t access)
throw(SystemException)
{
ASSERTP(access != READ, "file creation requires at least a write mode");
int fd = ::open(&path.toString(), makeFlags(access) | O_CREAT | O_TRUNC, 0666);
if(fd < 0)
throw SystemException(errno, _ << "cannot create \"" << path << "\"");
else
# if defined(__unix) || defined(__APPLE__)
return new UnixRandomAccessStream(fd);
# elif defined(__WIN32) || defined(__WIN64)
return new WinRandomAccessStream(fd);
# else
# error "Unsupported on this OS !"
# endif
}
示例6: MakeFullname
void SysSemaphore::Construct(const int32_t initialCount, const int32_t maxCount, const wchar_t* pName, void* security)
{
if (nullptr != pName)
{
std::wstring fullName = MakeFullname(pName);
m_handle = CreateSemaphore(reinterpret_cast<LPSECURITY_ATTRIBUTES>(security), initialCount, maxCount, fullName.c_str());
}
else
{
m_handle = CreateSemaphore(reinterpret_cast<LPSECURITY_ATTRIBUTES>(security), initialCount, maxCount, pName);
}
if (nullptr == m_handle)
{
throw SystemException("Couldn't create a new semaphore");
}
}
示例7: parseEmfObject
void parseEmfObject(const std::string& objectSerialized, T*& object_ptr, const std::string msgComp=std::string()) {
object_ptr = NULL;
try {
//CREATE DATA MODEL
T tmpObject;
ecore::EPackage_ptr ecorePackage = tmpObject._eClass()->getEPackage();
ecorecpp::MetaModelRepository::_instance()->load(ecorePackage);
//Parse the model
ecorecpp::parser::parser parser;
object_ptr = parser.load_str(objectSerialized)->as< T >();
}
catch (std::exception& e) {
throw SystemException(ERRCODE_INVDATA, msgComp);
}
}
示例8: mapPrio
void ThreadImpl::setPriorityImpl(int prio)
{
if (prio != _pData->prio)
{
_pData->prio = prio;
_pData->policy = SCHED_OTHER;
if (isRunningImpl())
{
struct sched_param par; struct MyStruct
{
};
par.sched_priority = mapPrio(_pData->prio, SCHED_OTHER);
if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
throw SystemException("cannot set thread priority");
}
}
}
示例9: readAll
static string readAll(int fd) {
string result;
char buf[1024 * 32];
ssize_t ret;
while (true) {
do {
ret = read(fd, buf, sizeof(buf));
} while (ret == -1 && errno == EINTR);
if (ret == 0) {
break;
} else if (ret == -1) {
throw SystemException("Cannot read from socket", errno);
} else {
result.append(buf, ret);
}
}
return result;
}
示例10: GetCurrentDirectoryW
std::string PathImpl::currentImpl()
{
std::string result;
DWORD len = GetCurrentDirectoryW(0, NULL);
if (len > 0)
{
Buffer<wchar_t> buffer(len);
DWORD n = GetCurrentDirectoryW(len, buffer.begin());
if (n > 0 && n <= len)
{
UnicodeConverter::toUTF8(buffer.begin(), result);
if (result[result.size() - 1] != '\\')
result.append("\\");
return result;
}
}
throw SystemException("Cannot get current directory");
}
示例11: defined
RWLockImpl::RWLockImpl()
{
#if defined(POCO_VXWORKS)
// This workaround is for VxWorks 5.x where
// pthread_mutex_init() won't properly initialize the mutex
// resulting in a subsequent freeze in pthread_mutex_destroy()
// if the mutex has never been used.
std::memset(&_mutex, 0, sizeof(_mutex));
#endif
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
if (pthread_mutex_init(&_mutex, &attr))
{
pthread_mutexattr_destroy(&attr);
throw SystemException("cannot create mutex");
}
pthread_mutexattr_destroy(&attr);
}
示例12: switch
bool MutexImpl::tryLockImpl()
{
switch (WaitForSingleObject(_mutex, 0))
{
case WAIT_TIMEOUT:
return false;
case WAIT_OBJECT_0:
if (!_recursive && _lockCount > 0)
{
ReleaseMutex(_mutex);
return false;
}
++_lockCount;
return true;
default:
throw SystemException("cannot lock mutex");
}
}
示例13: switch
bool RWLockImpl::tryReadLockImpl()
{
HANDLE h[2];
h[0] = _mutex;
h[1] = _readEvent;
switch (WaitForMultipleObjects(2, h, TRUE, 1))
{
case WAIT_OBJECT_0:
case WAIT_OBJECT_0 + 1:
++_readers;
ResetEvent(_writeEvent);
ReleaseMutex(_mutex);
return true;
case WAIT_TIMEOUT:
return false;
default:
throw SystemException("cannot lock reader/writer lock");
}
}
示例14: while
void Directory::Iterator::go(void) {
errno = 0;
while(true) {
struct dirent *dirent = readdir((DIR *)dir);
if(dirent) {
if(cstring(dirent->d_name) != "." && cstring(dirent->d_name) != "..") {
file = FileItem::get(path / dirent->d_name);
return;
}
}
else {
if(errno)
throw SystemException(errno, "file");
else
file = 0;
break;
}
}
}
示例15: _name
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void*):
_name(file.path()),
_memHandle(INVALID_HANDLE_VALUE),
_fileHandle(INVALID_HANDLE_VALUE),
_size(0),
_mode(PAGE_READONLY),
_address(0)
{
if (!file.exists() || !file.isFile())
throw FileNotFoundException(_name);
_size = static_cast<DWORD>(file.getSize());
DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
DWORD fileMode = GENERIC_READ;
if (mode == SharedMemory::AM_WRITE)
{
_mode = PAGE_READWRITE;
fileMode |= GENERIC_WRITE;
}
#if defined (POCO_WIN32_UTF8)
std::wstring utf16name;
UnicodeConverter::toUTF16(_name, utf16name);
_fileHandle = CreateFileW(utf16name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
#else
_fileHandle = CreateFileA(_name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
#endif
if (_fileHandle == INVALID_HANDLE_VALUE)
throw OpenFileException("Cannot open memory mapped file", _name);
_memHandle = CreateFileMapping(_fileHandle, NULL, _mode, 0, 0, NULL);
if (!_memHandle)
{
CloseHandle(_fileHandle);
_fileHandle = INVALID_HANDLE_VALUE;
throw SystemException("Cannot map file into shared memory", _name);
}
map();
}