//Checks validity of the file and also if the defaultNameSpace is declared or not. bool TandemReader::checkValidity(const std::string &file) { bool isvalid; std::ifstream fileIn(file.c_str(), std::ios::in); if (!fileIn) { ostringstream temp; temp << "Error : can not open file " << file << std::endl; throw MyException(temp.str()); } std::string line,line_xml,line_bioml; if (!getline(fileIn, line)) { ostringstream temp; temp << "Error : can not read file " << file << std::endl; throw MyException(temp.str()); } if (line.find("<?xml") != std::string::npos) { getline(fileIn, line_xml); getline(fileIn, line_bioml); if (line_xml.find("tandem") == std::string::npos||line_bioml.find("<bioml") == std::string::npos) { std::cerr << "XML file not generated by X!tandem: " << file << std::endl; isvalid = false; } else { isvalid=true; } } else { isvalid = false; } fileIn.close(); return isvalid; }
int main() { try { throw MyException(); } catch (std::exception & ex) { std::cout << "Message: " << ex.what() << std::endl; } getchar(); }
void Sound::prepare(){ if(soundsLoaded){ al_reserve_samples(2); soundsPrepared = true; songInstance = al_create_sample_instance(backgroundSong); al_set_sample_instance_playmode(songInstance, ALLEGRO_PLAYMODE_LOOP); al_attach_sample_instance_to_mixer(songInstance, al_get_default_mixer()); } else throw MyException("Sounds was not attached."); }
SymbolType *UnaryOpNode::getType(){ if(nodeType) return nodeType; SymbolType *type = operand->getType(); Values operation = token->value; switch(operation){ case factor: if(!dynamic_cast<PointerSymbol*>(type)) throw MyException("Type of unary operation is not a pointer", token); nodeType = dynamic_cast<PointerSymbol*>(type)->pointer; return nodeType; case b_and: if(!operand->isLvalue()) throw MyException("Expression must be a modifiable lvalue", token->line, token->start); nodeType = new PointerSymbol(type); return nodeType; case b_not: operand = makeTypeCoerce(operand, type, IntType); break; case l_not: if(dynamic_cast<StructSymbol*>(type)) throw MyException("No operator \"!\" matches these operands operand types are: !" + type->name, token); break; case incr: case decr: if(!operand->isModifiableLvalue()) throw MyException("Expression must be a modifiable lvalue", token); break; case Values::minus: if(!type->canConvertTo(FloatType)) throw MyException("Expression must have arithmetical type", token); } nodeType = type; return type; }
void *LibLoader::getSym(void *inputPoint, const std::string &symName) { void *symbol; if (_libs.find(inputPoint) == _libs.end()) throw(MyException("No such lib loaded dude..")); #ifdef __unix symbol = dlsym(inputPoint, symName.c_str()); #elif _WIN32 symbol = GetProcAddress((HMODULE)inputPoint, symName.c_str()); #endif return symbol; }
/** * \fn void MainWindow::saveWorkspaceAs() * \brief Fontion de sauvegarde (Save As..) * Slot faisant appelle à la fonction de sauvegarde du Workspace en passant en argument le chemin de sauvegarde choisi par l'utilisateur. */ void MainWindow::saveWorkspaceAs() { QString dossier = QFileDialog::getSaveFileName(ui->centralwidget, "Save workspace as...", QString(), "*.*"); QDir workFolder(dossier); if(!workFolder.mkpath(dossier)) throw MyException("An error occured while creating the workspace directory"); else { NoteManager::getInstance().setPath(QString(dossier)+"/"); QMessageBox::information(ui->centralwidget,"Information","Le chemin est :"+NoteManager::getInstance().getPath()); Workspace::getInstance().saveInFile(); } }
/** * \fn QString MainWindow::getPath() const * \brief Récupérer un chemin défini par l'utilisateur. * \return Retourne le chemin choisi. * Methode servant à recupérer le chemin de sauvegarde des fichiers par l'intermédiaire d'une boîte de dialogue. */ QString MainWindow::getPath() const { QString dossier = QFileDialog::getSaveFileName(ui->centralwidget, "Save a workspace", QString(), "*.*"); if(dossier=="") return ""; QDir workFolder(dossier); if(!workFolder.mkpath(dossier)) throw MyException("An error occured while creating the workspace directory"); else { return QString(dossier); } }
Node *Node::makeTypeCoerce(Node *expr, SymbolType *from, SymbolType *to){ if(!from->canConvertTo(to)) throw MyException("Cannot perform conversion", expr->token); if(from == to || *from == to) return expr; if (!dynamic_cast<ScalarSymbol*>(from) || !dynamic_cast<ScalarSymbol*>(to)) return expr; else { if(typePriority[to] - typePriority[from] == 1) return new CastNode(0, expr, to); return new CastNode(0, makeTypeCoerce(expr, from, IntType), FloatType); } }
void handler(const std::string& msg, const char* file, int line) { const int max_frames = 20; void *frames[max_frames]; int num_frames = backtrace(frames, max_frames); char** frame_strings = backtrace_symbols(frames, num_frames); std::stringstream buffer; buffer << msg << " at " << file << ":" << line << "\n"; buffer << "Stack trace below:\n"; for (int i = 1; i < num_frames; ++i) buffer << frame_strings[i] << "\n"; free(frame_strings); throw MyException(buffer.str()); }
void Params::set_input_dir(const std::string &input_dir_) throw (std::exception){ input_dir = input_dir_; if( input_dir.at(input_dir.length()-1 )!='/' ) input_dir += "/"; clusters_old = input_dir + "clusters.dmp"; headers_old = input_dir + "headers.dmp"; aln_dir_old = input_dir + "alignments/"; dbsorted_old = input_dir + "db_sorted.fas"; if( !Params::exists( clusters_old.c_str() ) ) throw MyException("The clusters file '%s' in the input directory does not exist!", clusters_old.c_str()); if( !Params::exists( aln_dir_old.c_str() ) ) throw MyException("No directory with alignments '%s' exists in the input directory!", aln_dir_old.c_str()); if( !Params::exists( headers_old.c_str() ) ) throw MyException("The headers file '%s' in the input directory does not exist!", headers_old.c_str()); // if( !Params::exists( dbsorted_old.c_str() ) ) // throw MyException("The sorted db file '%s' in the input directory does not exist!", headers_old.c_str()); }
T List<T>::get(const int& index) { if(isEmpty()) { throw MyException("Attempt to access element in an empty list"); } else { // Check for index out of bounds int count = 0; Queue<T> temp1; temp1 = *queue; while(!(temp1.isEmpty())) { count++; temp1.dequeue(); } if((count-1) < index || index < 0 || index != static_cast<int>(index)) { throw MyException("Index out of bounds or invalid"); } // Get value Queue<T> temp2; temp2 = *queue; int i = 0; while(i < (index)) { temp2.dequeue(); ++i; } return temp2.dequeue(); } }
// added by shenzhi for MSVC void ModelDB::SearchDirectory(char *pathname) { long handle; struct _finddata_t filestruct; //info for the file(or directory) char path_search[500]; // start the searching, find the first file or subdirectory under current path // "*" represents "search for everything", filestruct keeps the searching results handle = _findfirst("*", &filestruct); // if handle == -1, the directory is empty, stop search and return // ERROR MESSAGE 12 if((handle == -1)) throw MyException("Wrong model file or path value"); do{ // check whether the first object is a directory (filestruct.name is the pathname) if(::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_DIRECTORY) { // if it is a directory, skip it; // the code commented below is to read recursively under the directory. /* // if it is a directory, enter it and recursively call search_directory // note: skip "." or ".." files if(filestruct.name[0] != '.') { _chdir(filestruct.name); SearchDirectory(pathname); // after searching, go back up a level _chdir(".."); } */ } // if it is a file, and not ending with ~ else if(filestruct.name[strlen(filestruct.name)-1]!='~') { // get the full path _getcwd(path_search, 500); // then get the pathname for the file (including the filename) strcat(path_search,"\\"); strcat(path_search,filestruct.name); // parse the file string modelID(filestruct.name); parseSingleModelFile(path_search, modelID); } } while (_findnext(handle, &filestruct)==0); _findclose(handle); }
void ParsingArithmeticExpressions::Calculation() { while (*myPtr) { if (*myPtr == ')'){ stChar.Push(*myPtr); --myPtr; Calculation(); } else if (*myPtr == '('){ --myPtr; break; } else if (TokenTypeNumber(*myPtr)){ Number(); if (!TokenTypeOperator(*myPtr)){ if (stChar.Peek() == ')') throw MyException("Ошибка. Между открывающей и закрывающей скобкой отсутствует выражение.", myPtr, Expression + 1); else throw MyException("Ошибка. Отсутствует выражение.", nullptr, Expression + 1); } } else if (*myPtr == '+' || *myPtr == '-'){ MultiplicationDivision(); stChar.Push(*myPtr); --myPtr; Number(); } else if (*myPtr == '*' || *myPtr == '/' || *myPtr == '^'){ stChar.Push(*myPtr); --myPtr; Number(); } } MultiplicationDivision(); AdditionSubtraction(); }
void *LibLoader::getFromPath(const std::string & path) const { std::map<void *, std::string>::const_iterator it = _libs.begin(); std::map<void *, std::string>::const_iterator ite = _libs.end(); std::cout << "get from path: " << path << "$" << std::endl; while (it != ite) { if (it->second == path) return (it->first); else std::cout << "val: " << it->second << std::endl; ++it; } throw(MyException("No such lib loaded dude..")); }
size_t Master::deHash(const std::string& str) { if (str.find_first_not_of(hash) != str.npos) { throw MyException("Unsupported character in hash string(" + str + ")"); return 0; } size_t val(0); for (int i(str.size()-1), n(hash.size()); i >= 0; --i) { val *= n; val += hash.find(str[i]); } return val; }
std::string PSMDescription::removePTMs(const string& peptide) { std::string peptideSequence = peptide; peptideSequence = peptide.substr(2, peptide.size()- 4); for (unsigned int ix = 0; ix < peptideSequence.size(); ++ix) { if (peptideSequence[ix] == '[') { size_t posEnd = peptideSequence.substr(ix).find_first_of(']'); if (posEnd == string::npos) { ostringstream temp; temp << "Error : Peptide sequence " << peptide << " contains an invalid modification" << endl; throw MyException(temp.str()); } else { peptideSequence.erase(ix--, posEnd + 1); } } } return peptide.substr(0,1) + std::string(".") + peptideSequence + std::string(".") + peptide.substr(peptide.size() - 1,1); }
int init_conn(CURL* eh, StringHash url, Conn* conn) { conn->easy = eh; conn->url = url; std::stringstream file_path; file_path << DEFAULT_OUTPUT_DIR << "/" << m_file_id; m_file_id += 1; string tmp_file_path =file_path.str(); conn->file_path = m_psp->add_string(&tmp_file_path); conn->output = fopen(tmp_file_path.c_str(), "w+"); if (NULL == conn->output) { throw MyException("@init_easy_handler@ can't open file " + tmp_file_path); } return 0; }
bool SpectrumFileList::initFromFile(const std::string& fileListFN) { std::ifstream specListFN(fileListFN.c_str()); std::string line; if (specListFN.is_open()) { while (getline(specListFN, line)) { std::string filePath; std::istringstream iss(line); iss >> filePath; addFile(filePath); } if (fileIndexVector_.size() == 0) { std::stringstream ss; ss << "(SpectrumFileList.cpp) no input files detected in " << fileListFN << std::endl; throw MyException(ss); } } else {
void ParsingArithmeticExpressions::Number() { if (TokenTypeNumber(*myPtr)){ double rez = 0.0; int index = 0; bool flag = false; while (*myPtr && (TokenTypeNumber(*myPtr))){ if (*myPtr == ','){ if (flag) throw MyException("Ошибка. Некорректная запись десятичной дроби.", myPtr, Expression + 1); // Если две запятых flag = true; } myPtr--; } rez = atof(myPtr + 1); stDou.Push(rez); } }
int main() { try { throw MyException(); } catch (BaseException* e) { std::cout << "BaseException" << std::endl; } catch (std::exception& e) { std::cout << "exception" << std::endl; } catch (...) { std::cout << "catch all" << std::endl; } return 0; }
Node* TernaryOpNode::calculate() { if(*condition->token == T_INTEGER){ if(dynamic_cast<IntNumber*>(condition->token)->v2) return left; else return right; } else if(*condition->token == T_FLOAT){ if(dynamic_cast<FloatNumber*>(condition->token)->v2) return left; else return right; } else if(*condition->token == T_CHAR){ if(dynamic_cast<Char*>(condition->token)->v2) return left; else return right; } else throw MyException("Wrong call of high-level optimizer (const folding)", token); }
void MsgfplusReader::searchEngineSpecificParsing( const ::mzIdentML_ns::SpectrumIdentificationItemType & item, const int itemCount) { // First, check whether addFeatures was set to 1, in MS-GF+ if (!additionalMsgfFeatures) { BOOST_FOREACH (const ::mzIdentML_ns::UserParamType & up, item.userParam()) { if (up.value().present()) { std::string param_name(up.name().c_str()); // Check whether the mzid-file seem to include the additional features if (param_name == "ExplainedIonCurrentRatio") { // If one additional feature is found additionalMsgfFeatures = true; } } } if (!additionalMsgfFeatures) { // If no additional features were found in first PSM ostringstream temp; temp << "Error: No features for learning were found in the mzid-file." << " Run MS-GF+ with the addFeatures option set to 1." << std::endl; throw MyException(temp.str()); } }
void serialize(SF::Archive &ar) { RCF_ASSERT(ar.isRead() || ar.isWrite()); switch (mWhich) { case 0: ar & a1 & a2; break; case 1: ar & a1 & a2; throw MyException(); ar & a3; break; case 2: ar & a3; break; default: RCF_ASSERT(0); } }
void PolygonDialog::getCoords(Coordinates& coords) const { GtkTreeIter iter; gboolean valid; double x, y; valid = gtk_tree_model_get_iter_first (m_model, &iter); if(!valid) throw MyException("Adicione pelo menos uma coordenada.\n"); while(valid){ gtk_tree_model_get (m_model, &iter, 0, &x, 1, &y, -1); coords.emplace_back(x, y); valid = gtk_tree_model_iter_next (m_model, &iter); } }
double mySqrt(double x) throw(MyException) { if (x <= 0) { throw MyException(-1, "input invalide: must be >=0 but input: " + to_string(x)); // return 0; } double result; double delta; result = x; // do ten iterations int i; for (i = 0; i < 10; ++i) { if (result <= 0) { result = 0.1; } delta = x - (result * result); result = result + 0.5 * delta / result; } LOGD("mysqrt(%g) = %g", x, result); return result; }
void Compute::divideCompute() //除法类除法计算方法成员定义 { try { if(m_value2== 0) //如果除数为0,则抛出相应异常 { throw MyException("divisor is 0!"); } else //否则计算两数相除,并打印结果 { cout<<"m_value1/m_value2:"<<(m_value1/m_value2)<<endl; } }catch(MyException&e) //捕获对应异常类型 { string errorMessage = e.what(); //定义错误信息字符串对象,获取对应异常信息 cout<<errorMessage<<endl; //打印输出对应的异常信息 }catch(...) //捕获所有异常 { string errorMessage = "Don’t knowerror!";//捕获所有异常处理信息 cout<<errorMessage<<endl; } }
void TatortTendencyParser::writeMapToFile(map<int, vector< pair<int, double> > > *data, string filename) { ofstream ofile(filename); if (!ofile.is_open()) throw MyException("EXCEPTION: file '" + filename + "' could not be opened for writing"); // DATAFILE format: // key // numberOfEntries // int;double map<int, vector< pair<int, double> > >::iterator iter = data->begin(); while (iter != data->end()) { ofile << iter->first << endl; ofile << iter->second.size() << endl; for (unsigned int i = 0; i < iter->second.size(); i++) { ofile << iter->second[i].first << ";" << iter->second[i].second << endl; } iter++; } }
void Params::set_working_dir(const std::string &dir) throw (std::exception){ working_dir = dir; if( working_dir.at(working_dir.length()-1 )!='/' ) working_dir += "/"; if( !Params::is_directory( working_dir.c_str() ) ){ std::string cmd = "mkdir " + working_dir; int i = system( cmd.c_str() ); if (i != 0) throw MyException("The working directory '%s' could not be created!", working_dir.c_str()); //throw MyException("The denoted working directory '%s' does not exist or is not a directory!", working_dir.c_str()); } if (profile_query) dbsorted = working_dir + "db_cons_sorted.fas"; else dbsorted = working_dir + "db_sorted.fas"; if (profile_query) db = working_dir + "db_tmp.fas"; header_dmp_file = working_dir + "headers.dmp"; nodes_dmp_file = working_dir + "clusters.dmp"; refined_nodes_dmp_file = working_dir + "refined_clusters.dmp"; rep_db_file = working_dir + "representatives.fas"; if (cons_db_file == "") { cons_db_file = working_dir + "consensus.fas"; } set_tmp_dir(working_dir + "tmp" + "/"); }
void ParsingArithmeticExpressions::MultiplicationDivision() { double tmp1 = 0.0; double tmp2 = 0.0; while (stChar.Peek() == '*' || stChar.Peek() == '/' || stChar.Peek() == '^'){ switch (stChar.Pop()){ case'/': tmp1 = stDou.Pop(); tmp2 = stDou.Pop(); if (tmp2 == 0) throw MyException("Ошибка. Деление на ноль.", myPtr + 1, Expression + 1); stDou.Push(tmp1 / tmp2); break; case'*': tmp1 = stDou.Pop(); tmp2 = stDou.Pop(); stDou.Push(tmp1 * tmp2); break; case '^': Involution(); break; } } }
Node* UnaryOpNode::calculate(){ Values value = token->value; IntNumber *intToken = dynamic_cast<IntNumber*>(operand->token); FloatNumber *floatToken = dynamic_cast<FloatNumber*>(operand->token); Char *charToken = dynamic_cast<Char*>(operand->token); if(!(intToken || floatToken || charToken)) throw MyException("Wrong call of the optimizer (constants folding)"); if(value == b_not){ int t = intToken ? intToken->v2 : charToken->v2; return new IntNode(new IntNumber(token->start, 0, ~t)); } float t = intToken ? intToken->v2 : floatToken ? floatToken->v2 : charToken->v2; switch(value){ case l_not: return new IntNode(new IntNumber(token->start, 0, !t)); case minus: if(floatToken) return new FloatNode(new FloatNumber(token->start, 0, -t), 0); else return new IntNode(new IntNumber(token->start, 0, -(int)t)); default: return 0; } }