Skip to content

Commit

Permalink
Replace std::exit() calls by throw instead
Browse files Browse the repository at this point in the history
Fixes: #208
  • Loading branch information
SoapZA committed Jun 20, 2021
1 parent a5c3b3d commit 2e32b7a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/api/SamProgramChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// ***************************************************************************

#include "api/SamProgramChain.h"
#include "api/internal/utils/BamException_p.h"
using namespace BamTools;

#include <algorithm>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e32b7a

Please sign in to comment.