Skip to content

Commit

Permalink
Improved error message for Arithmetic_Evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-germer committed Nov 8, 2017
1 parent 9d39da9 commit af0ad40
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 43 deletions.
2 changes: 1 addition & 1 deletion source/ParameterWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ChooseModelDialog message handlers

int ChooseModelDialog::DoModal()
INT_PTR ChooseModelDialog::DoModal()
{
// TODO: Add your specialized code here and/or call the base class

Expand Down
2 changes: 1 addition & 1 deletion source/ParameterWizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ class ChooseModelDialog : public CDialog
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(ChooseModelDialog)
public:
virtual int DoModal();
virtual INT_PTR DoModal();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
Expand Down
2 changes: 1 addition & 1 deletion source/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#if !defined(AFX_STDAFX_H__9FB1EA59_6D94_4C6C_853F_BE12EC2EC3AC__INCLUDED_)
#define AFX_STDAFX_H__9FB1EA59_6D94_4C6C_853F_BE12EC2EC3AC__INCLUDED_

#define WINVER 0x0500
#define WINVER 0x0501

#if _MSC_VER > 1000
#pragma once
Expand Down
24 changes: 21 additions & 3 deletions source/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define EVALUATE_H

#include "scatmech.h"
#include "mist0.h"
#include <string>
#include <sstream>
#include <stack>
Expand All @@ -29,7 +30,7 @@ class EVAL_exception : public std::exception

EVAL_exception(const std::string& m)
{
message = "EVALUATE: " + m;
message = m;
}
virtual ~EVAL_exception() throw() {};

Expand Down Expand Up @@ -82,9 +83,26 @@ struct Variable_List {
class Arithmetic_Evaluator {
public:
Arithmetic_Evaluator(const char* str,const ValueVectorMap& _variables=ValueVectorMap())
: input(std::string(str)), variables(_variables) {evaluate();}
: input(std::string(str)), variables(_variables)
{
try {
evaluate();
}
catch (std::exception& e) {
throw MIST_exception("Error evaluating \"" + std::string(str) + "\": " + e.what());
}
}
Arithmetic_Evaluator(const std::string& str, const ValueVectorMap& _variables=ValueVectorMap())
: input(str), variables(_variables) {evaluate();}
: input(str), variables(_variables)
{
try {
evaluate();
}
catch (std::exception& e)
{
throw MIST_exception("Error evaluating \"" + str + "\": " + e.what());
}
}

const ValueVector& Value() const {return result;}

Expand Down
37 changes: 18 additions & 19 deletions source/loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,40 @@
using namespace std;
using namespace SCATMECH;

table_loop_variable::table_loop_variable(const string& _filename, Variable_List& _variable_list)
: filename(_filename), loop_variable(_variable_list)
{
string fname = find_file(filename);
ifstream_with_comments file(fname.c_str());

if (!file) throw MIST_exception("Cannot open file " + filename);
table_loop_variable::table_loop_variable(const string& _filename, Variable_List& _variable_list)
: filename(_filename), loop_variable(_variable_list)
{
string fname = find_file(filename);
ifstream_with_comments file(fname.c_str());
if (!file) throw MIST_exception("Cannot open file " + filename);

// Get header line...
string line = file.getstrline();
istringstream linestream(line);
int ncol=0;
istringstream linestream(line);
int ncol = 0;
string str;
while (linestream >> str,!linestream.fail()) {
while (linestream >> str, !linestream.fail()) {
vlist.push_back(str);
ncol++;
}

table.resize(ncol);
npoints =0;
npoints = 0;

for (int i=0; !file.fail() ;++i) {
for (int i = 0; !file.fail();++i) {
line = file.getstrline();
if (file.fail()) {
if (npoints==0) throw MIST_exception("No points in LIST loop.");

if (file.fail() || file.eof() || line.size()==0) {
if (npoints == 0) throw MIST_exception("No points in LIST loop.");
return;
}

istringstream linestream(line);
for (int j=0;j<ncol;++j) {
istringstream linestream(line);
for (int j = 0;j < ncol;++j) {
string temp;
double x;
linestream >> temp;
if (linestream.fail()) {

if (linestream.fail()||temp=="") {
if (j==0) {
if (npoints==0) throw MIST_exception("No points in LIST loop.");
return;
Expand Down
2 changes: 1 addition & 1 deletion source/mist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline bool iswspace(char c) {return (( c>=0x09&&c<=0x0D ) || c==0x20);}
//
// Define version number...
//
#define MIST_VERSION "4.01"
#define MIST_VERSION "4.11"

using namespace SCATMECH;
using namespace std;
Expand Down
17 changes: 0 additions & 17 deletions source/mist.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@
#include "evaluate.h"
#include "loops.h"

class MIST_exception : public std::exception
{
public:

MIST_exception(const std::string& m)
{
message = "MIST: " + m;
}
virtual ~MIST_exception() throw() {};

virtual const char *what() const throw() {
return message.c_str();
}

private:
std::string message;
};

class MIST_istream : public SCATMECH::istream_with_comments
{
Expand Down
18 changes: 18 additions & 0 deletions source/mist0.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ typedef std::deque<double> vdouble;
typedef std::deque<vdouble> vvdouble;
typedef std::deque<std::string> vstring;

class MIST_exception : public std::exception
{
public:

MIST_exception(const std::string& m)
{
message = "MIST: " + m;
}
virtual ~MIST_exception() throw() {};

virtual const char *what() const throw() {
return message.c_str();
}

private:
std::string message;
};

class MIST_Notifier {
public:
MIST_Notifier() {}
Expand Down
1 change: 1 addition & 0 deletions source/shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string>
#include "matrix3d.h"
#include "random.h"
#include <algorithm>

using namespace std;
using namespace SCATMECH;
Expand Down

0 comments on commit af0ad40

Please sign in to comment.