# HG changeset patch # User Jaroslav Hajek # Date 1256121474 -7200 # Node ID 32745d8e700130788cb7ca702a2c686e8d4b5984 # Parent 7bda650b691a21434cddb2452a0fbc77c558a9ca [mq]: errors.diff diff --git a/src/error.cc b/src/error.cc --- a/src/error.cc +++ b/src/error.cc @@ -204,7 +204,8 @@ static void verror (bool save_last_error, std::ostream& os, - const char *name, const char *id, const char *fmt, va_list args) + const char *name, const char *id, const char *fmt, va_list args, + bool with_cfn = false) { if (discard_error_messages) return; @@ -232,6 +233,24 @@ if (name) msg_string += std::string (name) + ": "; + if (with_cfn) + { + octave_function *curfcn = octave_call_stack::current (); + if (curfcn) + { + std::string cfn = curfcn->name (); + if (! cfn.empty ()) + { + cfn += ':'; + if (cfn.length () > base_msg.length () + || base_msg.compare (0, cfn.length (), cfn) != 0) + { + msg_string += cfn + ' '; + } + } + } + } + msg_string += base_msg + "\n"; if (! error_state && save_last_error) @@ -275,7 +294,7 @@ static void error_1 (std::ostream& os, const char *name, const char *id, - const char *fmt, va_list args) + const char *fmt, va_list args, bool with_cfn = false) { if (error_state != -2) { @@ -293,7 +312,7 @@ { char *tmp_fmt = strsave (fmt); tmp_fmt[len - 1] = '\0'; - verror (true, os, name, id, tmp_fmt, args); + verror (true, os, name, id, tmp_fmt, args, with_cfn); delete [] tmp_fmt; } @@ -301,7 +320,7 @@ } else { - verror (true, os, name, id, fmt, args); + verror (true, os, name, id, fmt, args, with_cfn); if (! error_state) error_state = 1; @@ -453,11 +472,11 @@ } static void -error_2 (const char *id, const char *fmt, va_list args) +error_2 (const char *id, const char *fmt, va_list args, bool with_cfn = false) { int init_state = error_state; - error_1 (std::cerr, "error", id, fmt, args); + error_1 (std::cerr, "error", id, fmt, args, with_cfn); if ((interactive || forced_interactive) && Vdebug_on_error && init_state == 0 @@ -492,6 +511,21 @@ } void +verror_with_cfn (const char *fmt, va_list args) +{ + error_2 ("", fmt, args, true); +} + +void +error_with_cfn (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + verror_with_cfn (fmt, args); + va_end (args); +} + +void verror_with_id (const char *id, const char *fmt, va_list args) { error_2 (id, fmt, args); @@ -506,6 +540,21 @@ va_end (args); } +void +verror_with_id_cfn (const char *id, const char *fmt, va_list args) +{ + error_2 (id, fmt, args, true); +} + +void +error_with_id_cfn (const char *id, const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + verror_with_id_cfn (id, fmt, args); + va_end (args); +} + static int check_state (const std::string& state) { diff --git a/src/error.h b/src/error.h --- a/src/error.h +++ b/src/error.h @@ -47,6 +47,9 @@ extern OCTINTERP_API void verror (const char *fmt, va_list args); extern OCTINTERP_API void error (const char *fmt, ...); +extern OCTINTERP_API void verror_with_cfn (const char *fmt, va_list args); +extern OCTINTERP_API void error_with_cfn (const char *fmt, ...); + extern OCTINTERP_API void vparse_error (const char *fmt, va_list args); extern OCTINTERP_API void parse_error (const char *fmt, ...); @@ -75,6 +78,12 @@ error_with_id (const char *id, const char *fmt, ...); extern OCTINTERP_API void +verror_with_id_cfn (const char *id, const char *fmt, va_list args); + +extern OCTINTERP_API void +error_with_id_cfn (const char *id, const char *fmt, ...); + +extern OCTINTERP_API void vparse_error_with_id (const char *id, const char *fmt, va_list args); extern OCTINTERP_API void diff --git a/src/octave.cc b/src/octave.cc --- a/src/octave.cc +++ b/src/octave.cc @@ -552,7 +552,7 @@ { va_list args; va_start (args, fmt); - verror (fmt, args); + verror_with_cfn (fmt, args); va_end (args); octave_throw_execution_exception (); diff --git a/src/ov-base.cc b/src/ov-base.cc --- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -395,7 +395,7 @@ if (! error_state) \ { \ if (require_int && D_NINT (d) != d) \ - error ("conversion of %g to " #T " value failed", d); \ + error_with_cfn ("conversion of %g to " #T " value failed", d); \ else if (d < MIN_LIMIT) \ retval = MIN_LIMIT; \ else if (d > MAX_LIMIT) \ diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -1594,7 +1594,7 @@ retval.xelem (i) = v; else { - error ("conversion to integer value failed"); + error_with_cfn ("conversion to integer value failed"); break; } } @@ -1676,7 +1676,7 @@ retval.xelem (i) = v; else { - error ("conversion to integer value failed"); + error_with_cfn ("conversion to integer value failed"); break; } }