Skip to content

Commit

Permalink
replace abort with runtime_error
Browse files Browse the repository at this point in the history
  • Loading branch information
carl committed May 30, 2018
1 parent be30d50 commit 5cc18b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
Expand Down
16 changes: 6 additions & 10 deletions cnpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include<cstring>
#include<iomanip>
#include<stdint.h>
#include<stdexcept>

char cnpy::BigEndianTest() {
int x = 1;
Expand Down Expand Up @@ -278,10 +279,7 @@ cnpy::npz_t cnpy::npz_load(std::string fname) {
cnpy::NpyArray cnpy::npz_load(std::string fname, std::string varname) {
FILE* fp = fopen(fname.c_str(),"rb");

if(!fp) {
printf("npz_load: Error! Unable to open file %s!\n",fname.c_str());
abort();
}
if(!fp) throw std::runtime_error("npz_load: Unable to open file "+fname);

while(1) {
std::vector<char> local_header(30);
Expand Down Expand Up @@ -321,18 +319,16 @@ cnpy::NpyArray cnpy::npz_load(std::string fname, std::string varname) {
}

fclose(fp);
printf("npz_load: Error! Variable name %s not found in %s!\n",varname.c_str(),fname.c_str());
abort();

//if we get here, we haven't found the variable in the file
throw std::runtime_error("npz_load: Variable name "+varname+" not found in "+fname);
}

cnpy::NpyArray cnpy::npy_load(std::string fname) {

FILE* fp = fopen(fname.c_str(), "rb");

if(!fp) {
printf("npy_load: Error! Unable to open file %s!\n",fname.c_str());
abort();
}
if(!fp) throw std::runtime_error("npy_load: Unable to open file "+fname);

NpyArray arr = load_the_npy_file(fp);

Expand Down

0 comments on commit 5cc18b0

Please sign in to comment.