Added myexeption to throw errors and show using MyExeption class.

This commit is contained in:
Christian
2019-03-01 11:12:44 +01:00
parent c0c6bf63a0
commit b19c03f524
10 changed files with 76 additions and 32 deletions
+10 -6
View File
@@ -9,6 +9,8 @@
#include "parameter.hpp"
#include "myexeption.h"
#include <iostream>
#include <sstream>
#include <stdlib.h>
@@ -20,6 +22,7 @@ using namespace std;
Parameter::Parameter() {
// Simulation Specs
seed = (int)getValue("seed");
numTotalElectrons = (long int)getValue("numTotalElectrons");
dt_s = getValue("dt_s");
@@ -45,10 +48,11 @@ Parameter::Parameter() {
// Output
numberZBins = getValue ("numberZBins");
}
}
double Parameter::getValue(std::string varName) {
double Parameter::getValue(string varName) {
char* ext = (char*)("cat");
char* str = strdup(varName.c_str());
double temp;
@@ -58,13 +62,13 @@ double Parameter::getValue(std::string varName) {
if (getenv("parpath") == NULL)
{
throw ("Parameter::value: Environment variable parpath not defined.");
throw MyException("Parameter::value: Environment variable parpath not defined.");
}
strcpy(fname, getenv("parpath"));
parfile = getenv("parfile");
if (parfile == NULL)
{
throw ("Parameter::value: Environment variable parfile not defined.");
throw MyException("Parameter::value: Environment variable parfile not defined.");
}
if (!ext)
{
@@ -75,7 +79,7 @@ double Parameter::getValue(std::string varName) {
{
stringstream ss;
ss<<"Parameter::value: Can not open file " <<fname<<".";
throw (ss.str());
throw MyException(ss.str());
}
while (!feof(fcat))
{
@@ -92,7 +96,7 @@ double Parameter::getValue(std::string varName) {
stringstream ss;
ss<<"Parameter::value: Variable "<<str<<" not found.";
throw (ss.str());
throw MyException(ss.str());
return 0;
}