summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
authorGravatarGravatar couriersud <couriersud@gmx.org>2019-11-05 00:08:52 +0100
committerGravatarGravatar couriersud <couriersud@gmx.org>2019-11-05 00:08:52 +0100
commit22e07506cc763caa4b26dbded8b14c466d8d6949 (patch)
tree73f98f3b1fdff8920669947594417d50e861a095 /src/lib
parentf315e47b89d62ddfe70a649dc439a80844d144c0 (diff)
netlist: more consistent exception handling. (nw)
Still not optimal, but better than what we had previously. No exception logging comes closer.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/netlist/analog/nlid_twoterm.h2
-rw-r--r--src/lib/netlist/devices/nld_log.cpp2
-rw-r--r--src/lib/netlist/devices/nlid_truthtable.cpp6
-rw-r--r--src/lib/netlist/nl_base.h2
-rw-r--r--src/lib/netlist/nl_parser.cpp1
-rw-r--r--src/lib/netlist/nl_setup.cpp20
-rw-r--r--src/lib/netlist/nltypes.h2
-rw-r--r--src/lib/netlist/plib/mat_cr.h4
-rw-r--r--src/lib/netlist/plib/parray.h4
-rw-r--r--src/lib/netlist/plib/pfunction.cpp8
-rw-r--r--src/lib/netlist/plib/poptions.cpp4
-rw-r--r--src/lib/netlist/plib/ppreprocessor.cpp2
-rw-r--r--src/lib/netlist/plib/pstonum.h4
-rw-r--r--src/lib/netlist/plib/pstring.h1
-rw-r--r--src/lib/netlist/prg/nltool.cpp28
-rw-r--r--src/lib/netlist/prg/nlwav.cpp2
16 files changed, 44 insertions, 48 deletions
diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h
index 45bf6d9dbf8..9c37f959f59 100644
--- a/src/lib/netlist/analog/nlid_twoterm.h
+++ b/src/lib/netlist/analog/nlid_twoterm.h
@@ -63,7 +63,7 @@ namespace analog
{
plib::unused_var(d1);
if (b)
- throw nl_exception("bselect with netlist and b==true");
+ plib::pthrow<nl_exception>("bselect with netlist and b==true");
return d2;
}
diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp
index 03165a573ef..5dd06c9beca 100644
--- a/src/lib/netlist/devices/nld_log.cpp
+++ b/src/lib/netlist/devices/nld_log.cpp
@@ -23,7 +23,7 @@ namespace netlist
, m_writer(&m_strm)
{
if (m_strm.fail())
- throw plib::file_open_e(plib::pfmt("{1}.log")(this->name()));
+ plib::pthrow<plib::file_open_e>(plib::pfmt("{1}.log")(this->name()));
m_strm.imbue(std::locale::classic());
}
diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp
index ef9850b1d05..695370d0737 100644
--- a/src/lib/netlist/devices/nlid_truthtable.cpp
+++ b/src/lib/netlist/devices/nlid_truthtable.cpp
@@ -244,7 +244,7 @@ namespace netlist
m_family_desc = anetlist.setup().family_from_model(m_family_name);
if (m_family_desc == nullptr)
- throw nl_exception("family description not found for {1}", m_family_name);
+ plib::pthrow<nl_exception>("family description not found for {1}", m_family_name);
return pool().make_unique<tt_type>(anetlist, name, m_family_desc, *m_ttbl, m_desc);
}
@@ -353,7 +353,7 @@ void truthtable_parser::parseline(unsigned cur, std::vector<pstring> list,
{
// cutoff previous inputs and outputs for ignore
if (m_out_state[nstate] != m_out_state.mask() && m_out_state[nstate] != val)
- throw nl_exception(plib::pfmt("Error in truthtable: State {1:04} already set, {2} != {3}\n")
+ plib::pthrow<nl_exception>(plib::pfmt("Error in truthtable: State {1:04} already set, {2} != {3}\n")
.x(nstate.as_uint())(m_out_state[nstate])(val) );
m_out_state.set(nstate, val);
for (std::size_t j=0; j<m_NO; j++)
@@ -449,7 +449,7 @@ void truthtable_parser::parse(const std::vector<pstring> &truthtable)
for (size_t i=0; i<m_size; i++)
{
if (m_out_state[i] == m_out_state.mask())
- throw nl_exception(plib::pfmt("truthtable: found element not set {1}\n").x(i) );
+ plib::pthrow<nl_exception>(plib::pfmt("truthtable: found element not set {1}\n").x(i) );
m_out_state.set(i, m_out_state[i] | (ign[i] << m_NO));
}
}
diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h
index 5665e48d497..5e238c3db26 100644
--- a/src/lib/netlist/nl_base.h
+++ b/src/lib/netlist/nl_base.h
@@ -161,7 +161,7 @@ class NETLIB_NAME(name) : public device_t
//============================================================
#if defined(MAME_DEBUG) || (NL_DEBUG == true)
-#define nl_assert(x) do { if (1) if (!(x)) throw nl_exception(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0)
+#define nl_assert(x) do { if (1) if (!(x)) plib::pthrow<nl_exception>(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0)
#define NL_NOEXCEPT
#else
#define nl_assert(x) do { if (0) if (!(x)) { /*throw nl_exception(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); */} } while (0)
diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp
index bcbf6d83525..d07335f343b 100644
--- a/src/lib/netlist/nl_parser.cpp
+++ b/src/lib/netlist/nl_parser.cpp
@@ -20,7 +20,6 @@ void parser_t::verror(const pstring &msg)
{
m_setup.log().fatal("{1}", msg);
plib::pthrow<nl_exception>(plib::pfmt("{1}")(msg));
- //throw error;
}
bool parser_t::parse(const pstring &nlname)
diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp
index 67f441674b0..21c9bf02654 100644
--- a/src/lib/netlist/nl_setup.cpp
+++ b/src/lib/netlist/nl_setup.cpp
@@ -902,11 +902,11 @@ void models_t::register_model(const pstring &model_in)
{
auto pos = model_in.find(' ');
if (pos == pstring::npos)
- throw nl_exception(MF_UNABLE_TO_PARSE_MODEL_1(model_in));
+ plib::pthrow<nl_exception>(MF_UNABLE_TO_PARSE_MODEL_1(model_in));
pstring model = plib::ucase(plib::trim(plib::left(model_in, pos)));
pstring def = plib::trim(model_in.substr(pos + 1));
if (!m_models.insert({model, def}).second)
- throw nl_exception(MF_MODEL_ALREADY_EXISTS_1(model_in));
+ plib::pthrow<nl_exception>(MF_MODEL_ALREADY_EXISTS_1(model_in));
}
void models_t::model_parse(const pstring &model_in, model_map_t &map)
@@ -923,7 +923,7 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map)
key = plib::ucase(model);
auto i = m_models.find(key);
if (i == m_models.end())
- throw nl_exception(MF_MODEL_NOT_FOUND(model));
+ plib::pthrow<nl_exception>(MF_MODEL_NOT_FOUND(model));
model = i->second;
}
pstring xmodel = plib::left(model, pos);
@@ -936,12 +936,12 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map)
if (i != m_models.end())
model_parse(xmodel, map);
else
- throw nl_exception(MF_MODEL_NOT_FOUND(model_in));
+ plib::pthrow<nl_exception>(MF_MODEL_NOT_FOUND(model_in));
}
pstring remainder = plib::trim(model.substr(pos + 1));
if (!plib::endsWith(remainder, ")"))
- throw nl_exception(MF_MODEL_ERROR_1(model));
+ plib::pthrow<nl_exception>(MF_MODEL_ERROR_1(model));
// FIMXE: Not optimal
remainder = plib::left(remainder, remainder.size() - 1);
@@ -950,7 +950,7 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map)
{
auto pose = pe.find('=');
if (pose == pstring::npos)
- throw nl_exception(MF_MODEL_ERROR_ON_PAIR_1(model));
+ plib::pthrow<nl_exception>(MF_MODEL_ERROR_ON_PAIR_1(model));
map[plib::ucase(plib::left(pe, pose))] = pe.substr(pose + 1);
}
}
@@ -975,9 +975,9 @@ pstring models_t::value_str(const pstring &model, const pstring &entity)
pstring ret;
if (entity != plib::ucase(entity))
- throw nl_exception(MF_MODEL_PARAMETERS_NOT_UPPERCASE_1_2(entity, model_string(map)));
+ plib::pthrow<nl_exception>(MF_MODEL_PARAMETERS_NOT_UPPERCASE_1_2(entity, model_string(map)));
if (map.find(entity) == map.end())
- throw nl_exception(MF_ENTITY_1_NOT_FOUND_IN_MODEL_2(entity, model_string(map)));
+ plib::pthrow<nl_exception>(MF_ENTITY_1_NOT_FOUND_IN_MODEL_2(entity, model_string(map)));
else
ret = map[entity];
@@ -1008,7 +1008,7 @@ nl_fptype models_t::value(const pstring &model, const pstring &entity)
case 'a': factor = nlconst::magic(1e-18); break;
default:
if (*p < '0' || *p > '9')
- throw nl_exception(MF_UNKNOWN_NUMBER_FACTOR_IN_1(entity));
+ plib::pthrow<nl_exception>(MF_UNKNOWN_NUMBER_FACTOR_IN_1(entity));
}
if (factor != nlconst::one())
tmp = plib::left(tmp, tmp.size() - 1);
@@ -1017,7 +1017,7 @@ nl_fptype models_t::value(const pstring &model, const pstring &entity)
bool err(false);
auto val = plib::pstonum_ne<nl_fptype>(tmp, err);
if (err)
- throw nl_exception(MF_MODEL_NUMBER_CONVERSION_ERROR(entity, tmp, "double", model));
+ plib::pthrow<nl_exception>(MF_MODEL_NUMBER_CONVERSION_ERROR(entity, tmp, "double", model));
return val * factor;
}
diff --git a/src/lib/netlist/nltypes.h b/src/lib/netlist/nltypes.h
index a2ec1fa4ac1..1171d56cd34 100644
--- a/src/lib/netlist/nltypes.h
+++ b/src/lib/netlist/nltypes.h
@@ -61,7 +61,7 @@ namespace netlist
COPYASSIGNMOVE(callbacks_t, default)
/* logging callback */
- virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0;
+ virtual void vlog(const plib::plog_level &l, const pstring &ls) const noexcept = 0;
};
diff --git a/src/lib/netlist/plib/mat_cr.h b/src/lib/netlist/plib/mat_cr.h
index c6dabbb9b22..d87faef8225 100644
--- a/src/lib/netlist/plib/mat_cr.h
+++ b/src/lib/netlist/plib/mat_cr.h
@@ -114,7 +114,7 @@ namespace plib
{
C nz = 0;
if (nz_num != 0)
- throw pexception("build_from_mat only allowed on empty CR matrix");
+ pthrow<pexception>("build_from_mat only allowed on empty CR matrix");
for (std::size_t k=0; k < size(); k++)
{
row_idx[k] = nz;
@@ -189,7 +189,7 @@ namespace plib
while (col_idx[dp] < src.col_idx[sp])
A[dp++] = 0;
if (row_idx[r+1] <= dp || col_idx[dp] != src.col_idx[sp])
- throw plib::pexception("slim_copy_from error");
+ pthrow<pexception>("slim_copy_from error");
A[dp++] = src.A[sp];
}
/* fill remaining elements in row */
diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h
index 18367d161c0..174d047f35c 100644
--- a/src/lib/netlist/plib/parray.h
+++ b/src/lib/netlist/plib/parray.h
@@ -82,7 +82,7 @@ namespace plib {
{
if ((SIZE < 0 && size > SIZEABS())
|| (SIZE > 0 && size != SIZEABS()))
- throw plib::pexception("parray: size error " + plib::to_string(size) + ">" + plib::to_string(SIZE));
+ pthrow<pexception>("parray: size error " + plib::to_string(size) + ">" + plib::to_string(SIZE));
}
template <int X = SIZE >
@@ -91,7 +91,7 @@ namespace plib {
{
if ((SIZE < 0 && size > SIZEABS())
|| (SIZE > 0 && size != SIZEABS()))
- throw plib::pexception("parray: size error " + plib::to_string(size) + ">" + plib::to_string(SIZE));
+ pthrow<plib::pexception>("parray: size error " + plib::to_string(size) + ">" + plib::to_string(SIZE));
m_a.fill(val);
}
diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp
index 5ac7478e197..44b037e827b 100644
--- a/src/lib/netlist/plib/pfunction.cpp
+++ b/src/lib/netlist/plib/pfunction.cpp
@@ -79,16 +79,16 @@ namespace plib {
bool err(false);
rc.m_param = plib::pstonum_ne<decltype(rc.m_param)>(cmd, err);
if (err)
- throw plib::pexception(plib::pfmt("pfunction: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr));
+ pthrow<pexception>(plib::pfmt("pfunction: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr));
stk += 1;
}
}
if (stk < 1)
- throw plib::pexception(plib::pfmt("pfunction: stack underflow on token <{1}> in <{2}>")(cmd)(expr));
+ pthrow<pexception>(plib::pfmt("pfunction: stack underflow on token <{1}> in <{2}>")(cmd)(expr));
m_precompiled.push_back(rc);
}
if (stk != 1)
- throw plib::pexception(plib::pfmt("pfunction: stack count different to one on <{2}>")(expr));
+ pthrow<pexception>(plib::pfmt("pfunction: stack count different to one on <{2}>")(expr));
}
static int get_prio(const pstring &v)
@@ -110,7 +110,7 @@ namespace plib {
static pstring pop_check(std::stack<pstring> &stk, const pstring &expr)
{
if (stk.size() == 0)
- throw plib::pexception(plib::pfmt("pfunction: stack underflow during infix parsing of: <{1}>")(expr));
+ pthrow<pexception>(plib::pfmt("pfunction: stack underflow during infix parsing of: <{1}>")(expr));
pstring res = stk.top();
stk.pop();
return res;
diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp
index 06c2115d40a..941b55c5b94 100644
--- a/src/lib/netlist/plib/poptions.cpp
+++ b/src/lib/netlist/plib/poptions.cpp
@@ -82,7 +82,7 @@ namespace plib {
{
if (m_other_args != nullptr)
{
- throw pexception("other args can only be specified once!");
+ pthrow<pexception>("other args can only be specified once!");
}
else
{
@@ -90,7 +90,7 @@ namespace plib {
}
}
else
- throw pexception("found option with neither short or long tag!" );
+ pthrow<pexception>("found option with neither short or long tag!" );
}
}
}
diff --git a/src/lib/netlist/plib/ppreprocessor.cpp b/src/lib/netlist/plib/ppreprocessor.cpp
index 810e77e3d87..80564064bb2 100644
--- a/src/lib/netlist/plib/ppreprocessor.cpp
+++ b/src/lib/netlist/plib/ppreprocessor.cpp
@@ -67,7 +67,7 @@ namespace plib {
s = trail + plib::pfmt("{1}:{2}:0\n")(m_stack.back().m_name, m_stack.back().m_lineno) + s;
m_stack.pop_back();
}
- throw pexception("\n" + s + e + " " + m_line + "\n");
+ pthrow<pexception>("\n" + s + e + " " + m_line + "\n");
}
template <typename PP, typename L = ppreprocessor::string_list>
diff --git a/src/lib/netlist/plib/pstonum.h b/src/lib/netlist/plib/pstonum.h
index 11c83603cfa..65ec6355b38 100644
--- a/src/lib/netlist/plib/pstonum.h
+++ b/src/lib/netlist/plib/pstonum.h
@@ -106,11 +106,11 @@ namespace plib
//&& (ret == T(0) || plib::abs(ret) >= std::numeric_limits<T>::min() ))
{
if (cstr[idx] != 0)
- throw pexception(pstring("Continuation after numeric value ends: ") + pstring(cstr));
+ pthrow<pexception>(pstring("Continuation after numeric value ends: ") + pstring(cstr));
}
else
{
- throw pexception(pstring("Out of range: ") + pstring(cstr));
+ pthrow<pexception>(pstring("Out of range: ") + pstring(cstr));
}
return static_cast<T>(ret);
}
diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h
index 49905d9c54c..25e79f5bdec 100644
--- a/src/lib/netlist/plib/pstring.h
+++ b/src/lib/netlist/plib/pstring.h
@@ -113,6 +113,7 @@ public:
pstring_t(C (&string)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
{
static_assert(N > 0,"pstring from array of length 0");
+ // need std::exception since pexception depends on pstring
if (string[N-1] != 0)
throw std::exception();
m_str.assign(string, N - 1);
diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp
index ed4659a12b1..0bfb324c607 100644
--- a/src/lib/netlist/prg/nltool.cpp
+++ b/src/lib/netlist/prg/nltool.cpp
@@ -181,7 +181,7 @@ public:
, m_app(app)
{ }
- void vlog(const plib::plog_level &l, const pstring &ls) const override;
+ void vlog(const plib::plog_level &l, const pstring &ls) const noexcept override;
private:
tool_app_t &m_app;
@@ -266,7 +266,7 @@ public:
size += s->m_dt.size * s->m_count;
if (buf.size() != size)
- throw netlist::nl_exception("Size different during load state.");
+ plib::pthrow<netlist::nl_exception>("Size different during load state.");
char *p = buf.data();
@@ -288,7 +288,7 @@ protected:
private:
};
-void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls) const
+void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls) const noexcept
{
pstring err = plib::pfmt("{}: {}\n")(l.name())(ls.c_str());
if (l == plib::plog_level::WARNING)
@@ -296,12 +296,8 @@ void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls
if (l == plib::plog_level::ERROR)
m_app.m_errors++;
if (l == plib::plog_level::FATAL)
- {
m_app.m_errors++;
- throw netlist::nl_exception(err);
- }
- else
- m_app.pout("{}", err);
+ m_app.pout("{}", err);
}
struct input_t
@@ -316,7 +312,7 @@ struct input_t
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
int e = std::sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf.data(), &val);
if (e != 3)
- throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
+ plib::pthrow<netlist::nl_exception>(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
m_value = static_cast<nl_fptype>(val);
m_time = netlist::netlist_time::from_fp(t);
m_param = setup.find_param(pstring(buf.data()), true);
@@ -328,7 +324,7 @@ struct input_t
{
case netlist::param_t::STRING:
case netlist::param_t::POINTER:
- throw netlist::nl_exception(plib::pfmt("param {1} is not numeric\n")(m_param->name()));
+ plib::pthrow<netlist::nl_exception>(plib::pfmt("param {1} is not numeric\n")(m_param->name()));
case netlist::param_t::DOUBLE:
static_cast<netlist::param_fp_t*>(m_param)->setTo(m_value);
break;
@@ -353,7 +349,7 @@ static std::vector<input_t> read_input(const netlist::setup_t &setup, const pstr
{
plib::putf8_reader r = plib::putf8_reader(std::ifstream(plib::filesystem::u8path(fname)));
if (r.stream().fail())
- throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(fname));
+ plib::pthrow<netlist::nl_exception>(netlist::MF_FILE_OPEN_ERROR(fname));
r.stream().imbue(std::locale::classic());
pstring l;
while (r.readline(l))
@@ -410,7 +406,7 @@ void tool_app_t::run()
{
std::ifstream strm(plib::filesystem::u8path(opt_loadstate()));
if (strm.fail())
- throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(opt_loadstate()));
+ plib::pthrow<netlist::nl_exception>(netlist::MF_FILE_OPEN_ERROR(opt_loadstate()));
strm.imbue(std::locale::classic());
plib::pbinary_reader reader(strm);
std::vector<char> loadstate;
@@ -448,7 +444,7 @@ void tool_app_t::run()
auto savestate = nt.save_state();
std::ofstream strm(plib::filesystem::u8path(opt_savestate()), std::ios_base::binary);
if (strm.fail())
- throw plib::file_open_e(opt_savestate());
+ plib::pthrow<plib::file_open_e>(opt_savestate());
strm.imbue(std::locale::classic());
plib::pbinary_writer writer(strm);
@@ -496,14 +492,14 @@ void tool_app_t::validate()
//pout("Validation errors: {}\n", m_errors);
if (m_warnings + m_errors > 0)
- throw netlist::nl_exception("validation: {1} errors {2} warnings", m_errors, m_warnings);
+ plib::pthrow<netlist::nl_exception>("validation: {1} errors {2} warnings", m_errors, m_warnings);
}
void tool_app_t::static_compile()
{
if (!opt_dir.was_specified())
- throw netlist::nl_exception("--dir option needs to be specified");
+ plib::pthrow<netlist::nl_exception>("--dir option needs to be specified");
netlist_tool_t nt(*this, "netlist");
@@ -763,7 +759,7 @@ void tool_app_t::convert()
{
std::ifstream strm(plib::filesystem::u8path(opt_file()));
if (strm.fail())
- throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(opt_file()));
+ plib::pthrow<netlist::nl_exception>(netlist::MF_FILE_OPEN_ERROR(opt_file()));
strm.imbue(std::locale::classic());
plib::copystream(ostrm, strm);
}
diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp
index fdc038c68c9..4b8f1da0391 100644
--- a/src/lib/netlist/prg/nlwav.cpp
+++ b/src/lib/netlist/prg/nlwav.cpp
@@ -533,7 +533,7 @@ int nlwav_app::execute()
{
auto outstrm(std::ofstream(plib::filesystem::u8path(opt_out())));
if (outstrm.fail())
- throw plib::file_open_e(opt_out());
+ plib::pthrow<plib::file_open_e>(opt_out());
outstrm.imbue(std::locale::classic());
convert(outstrm);
}