Mercurial > hg > octave-image
changeset 489:737b8c27d24c
image: properly formatted error message does not need to error trace back
author | carandraug |
---|---|
date | Wed, 02 Nov 2011 19:19:06 +0000 |
parents | 7757170f02e6 |
children | 334b214e70e9 |
files | inst/iptcheckconn.m inst/iptcheckmap.m inst/iptcheckstrs.m |
diffstat | 3 files changed, 19 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/inst/iptcheckconn.m +++ b/inst/iptcheckconn.m @@ -46,25 +46,28 @@ base_msg = sprintf ("Function %s expected input number %d, %s, to be a valid connectivity specifier.\n ", ... func_name, pos, var_name); + ## error ends in \n so the back trace of the error is not show. This is on + ## purpose since the whole idea of this function is already to give a properly + ## formatted error message if (!any (strcmp (class (con), {'logical', 'double'})) || !isreal (con) || !isnumeric (con)) - error ("%sConnectivity must be a real number of the logical or double class.", base_msg); + error ("%sConnectivity must be a real number of the logical or double class.\n", base_msg); elseif (isscalar (con)) if (!any (con == [1 4 6 8 18 26])) - error ("%sIf connectivity is a scalar, must belong to the set [1 4 6 8 18 26].", base_msg); + error ("%sIf connectivity is a scalar, must belong to the set [1 4 6 8 18 26].\n", base_msg); endif elseif (ismatrix (con)) center_index = ceil(numel(con)/2); if (any (size (con) != 3)) - error ("%sIf connectivity is a matrix, all dimensions must have size 3.", base_msg); + error ("%sIf connectivity is a matrix, all dimensions must have size 3.\n", base_msg); elseif (!all (con(:) == 1 | con(:) == 0)) - error ("%sIf connectivity is a matrix, only 0 and 1 are valid.", base_msg); + error ("%sIf connectivity is a matrix, only 0 and 1 are valid.\n", base_msg); elseif (con(center_index) != 1) - error ("%sIf connectivity is a matrix, central element must be 1.", base_msg); + error ("%sIf connectivity is a matrix, central element must be 1.\n", base_msg); elseif (!all (con(1:center_index-1) == con(end:-1:center_index+1))) - error ("%sIf connectivity is a matrix, it must be symmetric relative to its center.", base_msg); + error ("%sIf connectivity is a matrix, it must be symmetric relative to its center.\n", base_msg); endif else - error ("%s", base_msg); + error ("%s\n", base_msg); endif endfunction
--- a/inst/iptcheckmap.m +++ b/inst/iptcheckmap.m @@ -40,9 +40,12 @@ error ("Argument pos must be a real positive integer"); endif + ## error ends in \n so the back trace of the error is not show. This is on + ## purpose since the whole idea of this function is already to give a properly + ## formatted error message if (!strcmp (class(in), "double") || columns (in) != 3 || ndims (in) != 2 || !isreal (in) || min (in(:) < 0 || max (in(:) > 1) - error ("Function %s expected input number %d, %s, to be a valid colormap.\n ... - Valid colormaps must be nonempty, double, 2-D matrices with 3 columns.", ... + error ("Function %s expected input number %d, %s, to be a valid colormap.\n... + Valid colormaps must be nonempty, double, 2-D matrices with 3 columns.\n", ... func_name, pos, var_name); endif
--- a/inst/iptcheckstrs.m +++ b/inst/iptcheckstrs.m @@ -46,12 +46,15 @@ idx = find (strcmpi (valid_str, in) == 1, 1, "first"); + ## error ends in \n so the back trace of the error is not show. This is on + ## purpose since the whole idea of this function is already to give a properly + ## formatted error message if (isempty (idx)) valid_str = cellfun (@(x) cstrcat (x, ", "), valid_str, "UniformOutput", false); valid_str = cstrcat (valid_str{:}); error("Function %s expected its %s input argument, %s, to match one of these strings:\n... %s\n... - The input, '%s', did not match any of the valid strings.", ... + The input, '%s', did not match any of the valid strings.\n", ... func_name, iptnum2ordinal (pos), var_name, valid_str(1:end-2), in); else out = valid_str{idx};