📄 mf_errprintf.hlp
字号:
{smcl}
{* 31mar2005}{...}
{cmd:help mata errprintf()}
{hline}
{* index errprintf()}{...}
{* index SMCL}{...}
{* index as error}{...}
{title:Title}
{p 4 4 2}
{bf:[M-5] errprintf() -- Format output and display as error message}
{title:Syntax}
{p 8 12 2}
{it:void}
{cmd:errprintf(}{it:string scalar fmt}{cmd:,}
{it:r1}{cmd:,}
{it:r2}{cmd:,}
...{cmd:,}
{it:rN}{cmd:)}
{title:Description}
{p 4 4 2}
{cmd:errprintf()} is a convenience tool for displaying an error message.
{p 4 4 2}
{cmd:errprintf(}...{cmd:)} is equivalent to
{cmd:printf(}{it:...}{cmd:)}
except that it executes
{cmd:displayas("error")}
before the {cmd:printf()} is executed;
see
{bf:{help mf_printf:[M-5] printf()}}
and
{bf:{help mf_displayas:[M-5] displayas()}}
{title:Remarks}
{p 4 4 2}
You have written a program. At one point in the code, you have variable
{cmd:fn} that should contain the name of an existing file:
{cmd:if (!fileexists(fn)) {c -(}}
// {it:you wish to display the error message}
// {it:file ____ not found}
{cmd:exit(601)}
{cmd:{c )-}}
{p 4 4 2}
One solution is
{cmd:if (!fileexists(fn)) {c -(}}
{cmd:displayas("error")}
{cmd:printf("file %s not found\n", fn)}
{cmd:exit(601)}
{cmd:{c )-}}
{p 4 4 2}
Equivalent is
{cmd:if (!fileexists(fn)) {c -(}}
{cmd:errprintf("file %s not found\n", fn)}
{cmd:exit(601)}
{cmd:{c )-}}
{p 4 4 2}
It is important that you either {cmd:displayas("error")} before using
{cmd:printf()} or that you use {cmd:errprintf()}, in order to ensure
that you error message is displayed (is not suppressed by a
{cmd:quietly}) and that it is displayed in red; see
{bf:{help mf_displayas:[M-5] displayas()}}.
{title:Conformability}
{p 4 8 2}
{cmd:errprintf(}{it:fmt}{cmd:,}
{it:r1}{cmd:,}
{it:r2}{cmd:,}
...{cmd:,}
{it:rN}{cmd:)}
{p_end}
{it:fmt}: 1 {it:x} 1
{it:r1}: 1 {it:x} 1
{it:r2}: 1 {it:x} 1
...
{it:rN}: 1 {it:x} 1
{it:result}: {it:void}
{title:Diagnostics}
{p 4 4 2}
{cmd:errprintf()} aborts with error if
a {cmd:%}{it:fmt} is misspecified, if a numeric {cmd:%}{it:fmt}
corresponds to a string result or a string {cmd:%}{it:fmt}
corresponds to a numeric result, or there are too few or too many
{cmd:%}{it:fmts} in {it:fmt} relative
to the number of {it:results} specified.
{title:Source code}
{p 4 4 2}
Function is built-in.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-5] errprintf()}
{p 4 13 2}
Online: help for
{bf:{help mf_printf:[M-5] printf()}},
{bf:{help mf_displayas:[M-5] displayas()}};
{bf:{help m4_io:[M-4] io}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -