From 2e32b7ada9896e9fa10406b5397890c0064da1cd Mon Sep 17 00:00:00 2001 From: David Seifert Date: Sun, 20 Jun 2021 21:25:04 +0200 Subject: [PATCH] Replace `std::exit()` calls by `throw` instead Fixes: #208 --- src/api/SamProgramChain.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/api/SamProgramChain.cpp b/src/api/SamProgramChain.cpp index b96fe49..6ad912e 100644 --- a/src/api/SamProgramChain.cpp +++ b/src/api/SamProgramChain.cpp @@ -8,6 +8,7 @@ // *************************************************************************** #include "api/SamProgramChain.h" +#include "api/internal/utils/BamException_p.h" using namespace BamTools; #include @@ -192,8 +193,8 @@ SamProgram& SamProgramChain::First() } // otherwise error - std::cerr << "SamProgramChain::First: could not find any record without a PP tag" << std::endl; - std::exit(EXIT_FAILURE); + throw Internal::BamException("SamProgramChain::First", + "could not find any record without a PP tag"); } /*! \fn const SamProgram& SamProgramChain::First() const @@ -221,8 +222,8 @@ const SamProgram& SamProgramChain::First() const } // otherwise error - std::cerr << "SamProgramChain::First: could not find any record without a PP tag" << std::endl; - std::exit(EXIT_FAILURE); + throw Internal::BamException("SamProgramChain::First", + "could not find any record without a PP tag"); } /*! \fn int SamProgramChain::IndexOf(const std::string& programId) const @@ -275,8 +276,7 @@ SamProgram& SamProgramChain::Last() } // otherwise error - std::cerr << "SamProgramChain::Last: could not determine last record" << std::endl; - std::exit(EXIT_FAILURE); + throw Internal::BamException("SamProgramChain::Last", "could not determine last record"); } /*! \fn const SamProgram& SamProgramChain::Last() const @@ -303,8 +303,7 @@ const SamProgram& SamProgramChain::Last() const } // otherwise error - std::cerr << "SamProgramChain::Last: could not determine last record" << std::endl; - std::exit(EXIT_FAILURE); + throw Internal::BamException("SamProgramChain::Last", "could not determine last record"); } /*! \fn const std::string SamProgramChain::NextIdFor(const std::string& programId) const @@ -357,8 +356,8 @@ SamProgram& SamProgramChain::operator[](const std::string& programId) // if record not found if (index == (int)m_data.size()) { - std::cerr << "SamProgramChain::operator[] - unknown programId: " << programId << std::endl; - std::exit(EXIT_FAILURE); + throw Internal::BamException("SamProgramChain::operator[]", + "unknown programId: " + programId); } // otherwise return program record at index