您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ system_error函数代码示例

51自学网 2021-06-03 08:38:40
  C++
这篇教程C++ system_error函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中system_error函数的典型用法代码示例。如果您正苦于以下问题:C++ system_error函数的具体用法?C++ system_error怎么用?C++ system_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了system_error函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: malloc

/* Allocate a block of storage; abort execution if it cannot be done. */static void *allocate_memory (size_t size) {   void *address = malloc(size);   if (address == NULL) {      system_error("memory allocation");   }   return address;}
开发者ID:brltty,项目名称:locktones,代码行数:8,


示例2: ref

bool loop_impl::run_once( bool block ){        if (block)        _sem.wait();    else {        if (!_sem.wait(0)) {            return false;        }    }    shared_ptr<task_t> task;    {        concurrency_task_queue::ref ref(_task_queue);        task = ref->front();        ref->pop();    }    if (task->empty()) {        throw system_error(-1, "you do run after ended!");    }    try    {        (*task)();    }    catch (std::exception &e)    {        LOG_ERROR(e.what());    }    return true;}
开发者ID:wsxiaoys,项目名称:MsgIO,代码行数:30,


示例3: PRE

/// Executes an external binary and replaces the current process.////// This differs from process::exec() in that this function reports errors/// caused by the exec(2) system call to let the caller decide how to handle/// them.////// This function must not use any of the logging features so that the output/// of the subprocess is not "polluted" by our own messages.////// This function must also not affect the global state of the current process/// as otherwise we would not be able to use vfork().  Only state stored in the/// stack can be touched.////// /param program The binary to execute./// /param args The arguments to pass to the binary, without the program name.////// /throw system_error If the exec(2) call fails.voidprocess::exec_unsafe(const fs::path& program, const args_vector& args){    PRE(args.size() < MAX_ARGS);    int original_errno = 0;    try {        const char* argv[MAX_ARGS + 1];        argv[0] = program.c_str();        for (args_vector::size_type i = 0; i < args.size(); i++)            argv[1 + i] = args[i].c_str();        argv[1 + args.size()] = NULL;        const int ret = ::execv(program.c_str(),                                (char* const*)(unsigned long)(const void*)argv);        original_errno = errno;        INV(ret == -1);        std::cerr << "Failed to execute " << program << ": "                  << std::strerror(original_errno) << "/n";    } catch (const std::runtime_error& error) {        std::cerr << "Failed to execute " << program << ": "                  << error.what() << "/n";        std::abort();    } catch (...) {        std::cerr << "Failed to execute " << program << "; got unexpected "            "exception during exec/n";        std::abort();    }    // We must do this here to prevent our exception from being caught by the    // generic handlers above.    INV(original_errno != 0);    throw system_error("Failed to execute " + program.str(), original_errno);}
开发者ID:racktopsystems,项目名称:kyua,代码行数:51,


示例4: set_piece_hashes

	TORRENT_DEPRECATED	void set_piece_hashes(create_torrent& t, std::wstring const& p, Fun f)	{		error_code ec;		set_piece_hashes_deprecated(t, p, f, ec);		if (ec) throw system_error(ec);	}
开发者ID:krattai,项目名称:AEBL,代码行数:7,


示例5: parent

    void parent(pid_t pid, int* cmd_stdout, int* cmd_stderr) {        /* We dont need input descriptors, we'll be only reading from        the child */        close(cmd_stderr[1]);        close(cmd_stdout[1]);        string buf = read_all(cmd_stderr[0]);        buf += read_all(cmd_stdout[0]);        /* We've read it all, not needed any more */        close(cmd_stderr[0]);        close(cmd_stdout[0]);        /* Clean up child's status */        int status;        if(waitpid(pid, &status, 0/*options*/) == -1)            throw system_error("waitpid", errno);#ifdef REPORT_COMPILER_EXIT_STATUS        /* Compiler process reported errors - throw exception */        stringstream exit_info;        if(WIFSIGNALED(status)) {            exit_info << "Compiler exited due to signal "<<                WTERMSIG(status) << endl;        }else if(WIFEXITED(status) && WEXITSTATUS(status) != 0){            exit_info << "Compiler exited normaly with status " <<                WEXITSTATUS(status) << endl;        }        buf.insert(0, exit_info.str() + "/n");#endif        if(!buf.empty()) {            throw compiler_error(buf);        }    }
开发者ID:rzymek,项目名称:cxxsp,代码行数:33,


示例6: write_galaxy

static int write_galaxy(const char *filename, struct galaxy *g){    FILE *fp;    if ((fp = open_file(filename, FMODE_WB)))    {        struct head H;        H.N_num = host_to_net_int(g->N_num);        H.S_num = host_to_net_int(g->S_num);        if (fwrite(&H, sizeof (struct head), 1, fp) == 1)        {            int i;            for (i = 0; i < g->N_num; ++i)                node_write_bin(g->N + i, fp);            for (i = 0; i < g->S_num; ++i)                star_write_bin(g->S + i, fp);        }        fclose(fp);        return 1;    }    else error("Galaxy file '%s': %s", filename, system_error());    return 0;}
开发者ID:johnh530,项目名称:electro,代码行数:29,


示例7: parse_galaxy

static int parse_galaxy(const char *filename, struct galaxy *g){    FILE *fp;    int i;    if ((fp = open_file(filename, FMODE_RB)))    {        struct head H;        if (fread(&H, sizeof (struct head), 1, fp) == 1)        {            g->magnitude = 1.0;            g->N_num     = ntohl(H.N_num);            g->S_num     = ntohl(H.S_num);            if ((g->N = (struct node *) calloc(g->N_num, sizeof(struct node))))                for (i = 0; i < g->N_num; ++i)                    node_parse_bin(g->N + i, fp);            if ((g->S = (struct star *) calloc(g->S_num, sizeof(struct star))))                for (i = 0; i < g->S_num; ++i)                    star_parse_bin(g->S + i, fp);        }        fclose(fp);        return 1;    }    else error("Galaxy file '%s': %s", filename, system_error());    return 0;}
开发者ID:johnh530,项目名称:electro,代码行数:31,


示例8: system_error

voidimpl::stream_capture::prepare(void){    if (pipe(m_pipefds) == -1)        throw system_error(IMPL_NAME "::stream_capture::prepare",                           "Failed to create pipe", errno);}
开发者ID:enukane,项目名称:netbsd-src,代码行数:7,


示例9: system_error

/** * Remove inotify watch */void inotify_watch::remove(bool force) {  if (inotify_rm_watch(m_fd, m_wd) == -1 && !force) {    throw system_error("Failed to remove inotify watch");  }  m_wd = -1;  m_mask = 0;}
开发者ID:JBouron,项目名称:polybar,代码行数:10,


示例10: system_error

// public emergency stopvoid slight_StepperManager::system_emergencystop() {    motor.stop();    motor.disable();    // something went wrong    error_type = ERROR_emergencystop;    system_error();}
开发者ID:s-light,项目名称:slight_StepperManager,代码行数:8,


示例11: copy_to_destination

  /**   * @copydoc   * data::output::copy_to_destination   */  virtual  void  copy_to_destination (   object_type const* src,   std::size_t src_size  ) final override  {    ::ssize_t swrote;    while (src_size > 0)    {      swrote = ::write(STDOUT_FILENO, src, src_size * sizeof(ObjectT));            if (swrote == 0)      {        throw out_of_space("End of file reached.");      }      else      if (swrote == -1)      {        throw system_error("write");      }      src += static_cast<std::size_t>(swrote);      src_size -= static_cast<std::size_t>(swrote);    }  }
开发者ID:fumu-no-kagomeko,项目名称:libkueea-system-file,代码行数:31,


示例12: convert

	basic_string< TargetChar > convert( const basic_string< SourceChar > &sourceString,			size_t ( *convertFunction )( TargetChar *dst, const SourceChar **src, size_t len, mbstate_t *state )) {		constexpr auto LENGTH_ERROR = static_cast< size_t >( -1 );		mbstate_t state = mbstate_t();		// Find out how much space we need:		const SourceChar *sourceStringData = sourceString.data();		size_t expectedTargetStringLength = convertFunction( nullptr, &sourceStringData, sourceString.length(), &state );		if ( expectedTargetStringLength == LENGTH_ERROR )			throw make_errno_system_error();		// Convert the string:		basic_string< TargetChar > targetString( expectedTargetStringLength, TargetChar() );		size_t actualTargetStringLength = convertFunction( &targetString[ 0 ], &sourceStringData, sourceString.length(), &state );		if ( actualTargetStringLength == LENGTH_ERROR )			throw make_errno_system_error();		// Could all characters be converted?		if ( expectedTargetStringLength != actualTargetStringLength )			throw system_error( make_error_code( errc::illegal_byte_sequence ));		return targetString;	}
开发者ID:petermost,项目名称:CppAidKit,代码行数:28,


示例13: setup_input

//!//! /brief Configures child process' input streams.//!//! Sets up the current process' input streams to behave according to the//! information in the /a info map.  /a closeflags is modified to reflect//! those descriptors that should not be closed because they where modified//! by the function.//!//! Modifies the current execution environment, so this should only be run//! on the child process after the fork(2) has happened.//!//! /throw system_error If any error occurs during the configuration.//!inlinevoidsetup_input(info_map& info, bool* closeflags, int maxdescs){    for (info_map::iterator iter = info.begin(); iter != info.end(); iter++) {        int d = (*iter).first;        stream_info& si = (*iter).second;        BOOST_ASSERT(d < maxdescs);        closeflags[d] = false;        if (si.m_type == stream_info::use_file) {            int fd = ::open(si.m_file.c_str(), O_RDONLY);            if (fd == -1)                boost::throw_exception                    (system_error("boost::process::detail::setup_input",                                  "open(2) of " + si.m_file + " failed",                                  errno));            if (fd != d) {                file_handle h(fd);                h.posix_remap(d);                h.disown();            }        } else if (si.m_type == stream_info::use_handle) {            if (si.m_handle.get() != d)                si.m_handle.posix_remap(d);        } else if (si.m_type == stream_info::use_pipe) {            si.m_pipe->wend().close();            if (d != si.m_pipe->rend().get())                si.m_pipe->rend().posix_remap(d);        } else            BOOST_ASSERT(si.m_type == stream_info::inherit);    }}
开发者ID:iamnilay3,项目名称:openlierox,代码行数:47,


示例14: find_correct_splitedge

  leptrfind_correct_splitedge(evfptr oldsplitedge,vertype breakpos){  leptr forwardle,backle,oldsplitle;  vertype nearpt;		/* dummy here since we know breakpos */  evfptr splitedge;  Boolean searchforwards = TRUE,searchbackwards = TRUE;  double dummyt;  ;  /* change this call to be pt_near_lineseg_3d and make sure *that* routine */  /* doesn't let t+- tol's to slip through anymore, ok? */  oldsplitle = oldsplitedge->le1;  if (pt_near_lineseg_3d(oldsplitle->facevert->pos,			 oldsplitle->next->facevert->pos,breakpos,nearpt,			 &dummyt,Ptonlinetol))      return(oldsplitle);#ifdef debug  printf("/t/t*** Doing find_correct_splitedge!/n/n");#endif  forwardle = oldsplitle->next;  backle = oldsplitle->prev;  while (searchforwards || searchbackwards)  {    if (searchforwards)    {      if (pt_near_lineseg_3d(forwardle->facevert->pos,			     Twin_le(forwardle)->facevert->pos,			     breakpos,nearpt,&dummyt,Ptonlinetol))	return(forwardle);      else      {	forwardle = forwardle->next;	/* make sure you didn't branch... if you did you're no longer on */	/* the broken up edge. */	if ((forwardle == oldsplitle) || 	    ((Twin_le(Twin_le(forwardle->prev)->prev)) != forwardle))	  searchforwards = FALSE;      }    }    if (searchbackwards)    {      if (pt_near_lineseg_3d(backle->facevert->pos,			     Twin_le(backle)->facevert->pos,			     breakpos,nearpt,&dummyt,Ptonlinetol))	return(backle);      else      {	backle = backle->prev;	/* make sure you didn't branch... if you did you're no longer on */	/* the broken up edge. */	if ((backle == oldsplitle) || 	    ((Twin_le(Twin_le(backle->next)->next)) != backle))	  searchbackwards = FALSE;      }    }  }  system_error("find_correct_splitedge: break edge search failure!!/n");  return 0; 			// We'll never get here... -- LJE}
开发者ID:cutplane,项目名称:cutplane,代码行数:59,


示例15: system_error

void thread::detach() {  if (joinable()) {    m_handle = thread_uninitialized;  } else {    throw system_error(make_error_code(errc::invalid_argument),                       "Can not detach an unjoinable thread.");  }}
开发者ID:AdamRLukaitis,项目名称:RIOT,代码行数:8,


示例16: get_group_name

/* Return the name of group GID. The return value is a buffer * that the caller must deallocate with free. GID must be a * valid group ID. */static char* get_group_name(gid_t gid){    struct group* entry = getgrgid(gid);    if (entry == NULL) {        system_error("getgrgid");    }    return xstrdup(entry->gr_name);}
开发者ID:pandolia,项目名称:advanced-linux-program,代码行数:11,


示例17: strncpy

 void unix_socket::bind(const std::string& sun_path) {     struct sockaddr_un local;     local.sun_family = AF_UNIX;     strncpy(local.sun_path,sun_path.c_str(), UNIX_PATH_MAX);     unlink(local.sun_path);      if(::bind(sockfd, reinterpret_cast<sockaddr*>(&local), sizeof(local)) == -1)         throw system_error("bind",errno); }
开发者ID:rzymek,项目名称:cxxsp,代码行数:8,


示例18: system_error

 void compiler::process(const string& cpp_path, const string& out_path, const vector<string>& params) {     int cmd_stdout[2];//0-read, 1-write;     int cmd_stderr[2];//0-read, 1-write;     if(pipe(cmd_stdout) == -1 || pipe(cmd_stderr) == -1)             throw system_error("pipe",errno);     pid_t pid = fork();     switch(pid){         case -1:             throw system_error("fork", errno);         case 0: //child             setup_descriptors(cmd_stdout, cmd_stderr);             compiler_main(cpp_path, out_path, params);                         break;         default:             parent(pid, cmd_stdout, cmd_stderr);     } }
开发者ID:rzymek,项目名称:cxxsp,代码行数:17,


示例19: get_group_name

/* Return the name of group GID. The return value is a buffer that the * caller must allocate with free. GID must be a valid group ID. */static char* get_group_name (gid_t gid){/*{{{*/    struct group* entry;    entry = getgrgid (gid);    if (entry == NULL)        system_error ("getgrgid");    return xstrdup (entry->gr_name);}/*}}}*/
开发者ID:flandershk,项目名称:advanced_linux_programming,代码行数:10,


示例20: get_user_name

/* Return the name of user UID. The return value is a buffer that the * caller must allocate with free. UID must be a valid user ID. */static char* get_user_name (uid_t uid){/*{{{*/    struct passwd* entry;    entry = getpwuid (uid);    if (entry == NULL)        system_error ("getpwuid");    return xstrdup (entry->pw_name);}/*}}}*/
开发者ID:flandershk,项目名称:advanced_linux_programming,代码行数:10,


示例21: throw

void Calculator::calculate_answer() throw(ZeroDivide){  if(expression==NULL) throw system_error("in void Calculator::calculate_answer(): call set_expression(const PreExpression& s, Expression& exp) before calling this metod");  if(has_answer==true) return;  expression->calculate_answer();  expression_history.add(*source,*expression);  has_answer=true;}
开发者ID:maximzavadskiy,项目名称:code-samples,代码行数:8,


示例22: add_magnet_uri

	torrent_handle add_magnet_uri(session& ses, std::string const& uri		, add_torrent_params const& p)	{		error_code ec;		torrent_handle ret = add_magnet_uri_deprecated(ses, uri, p, ec);		if (ec) throw system_error(ec);		return ret;	}
开发者ID:Athorcis,项目名称:libtorrent,代码行数:8,


示例23: dump_st_026

/* A核用户数据 */int dump_st_026(void){    char *p;    p = kmalloc(4096, GFP_KERNEL);    memset(p,1,4096);    system_error(0x88,1,2,p,4096);    return 0;}
开发者ID:samm-git,项目名称:e3372h-vendor-src,代码行数:9,


示例24: FMT_SYSTEM

void buffered_file::close() {  if (!file_)    return;  int result = FMT_SYSTEM(fclose(file_));  file_ = FMT_NULL;  if (result != 0)    FMT_THROW(system_error(errno, "cannot close file"));}
开发者ID:BombShen,项目名称:kbengine,代码行数:8,


示例25: FMT_RETRY

void file::dup2(int fd) {  int result = 0;  FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd)));  if (result == -1) {    FMT_THROW(system_error(errno,      "cannot duplicate file descriptor {} to {}", fd_, fd));  }}
开发者ID:BombShen,项目名称:kbengine,代码行数:8,


示例26: FMT_POSIX_CALL

file file::dup(int fd) {  // Don't retry as dup doesn't return EINTR.  // http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html  int new_fd = FMT_POSIX_CALL(dup(fd));  if (new_fd == -1)    FMT_THROW(system_error(errno, "cannot duplicate file descriptor {}", fd));  return file(new_fd);}
开发者ID:BombShen,项目名称:kbengine,代码行数:8,


示例27: defined

handle handle::dup() const {  if (!*this) BOOST_THROW_EXCEPTION(handle_is_closed_error());#if defined(BOOST_POSIX_API)  const implementation fd = ::fcntl(**this, F_DUPFD_CLOEXEC, 0);  if (fd < 0)    BOOST_THROW_EXCEPTION(system_error("fcntl")                          << system_error::handle(**this));#elif defined(BOOST_WINDOWS_API)  implementation fd;  if (!::DuplicateHandle(::GetCurrentProcess(), **this, ::GetCurrentProcess(),                         &fd, 0, /* not inheritable */ false,                         DUPLICATE_SAME_ACCESS)) {    BOOST_THROW_EXCEPTION(system_error("DuplicateHandle")                          << system_error::handle(**this));  }#endif  return handle(fd);}
开发者ID:bunsanorg,项目名称:process,代码行数:18,


示例28: BOOST_THROW_EXCEPTION

handle handle::dup2(const implementation new_fd) const {  if (!*this) BOOST_THROW_EXCEPTION(handle_is_closed_error());  const implementation fd = ::dup3(**this, new_fd, O_CLOEXEC);  if (fd < 0)    BOOST_THROW_EXCEPTION(system_error("dup3")                          << system_error::handle(**this)                          << system_error::new_handle(new_fd));  return handle(fd);}
开发者ID:bunsanorg,项目名称:process,代码行数:9,



注:本文中的system_error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ system_get_free_heap_size函数代码示例
C++ systemTime函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。