matlab prompt错误返回,Display error message with identifier and return to

mexErrMsgIdAndTxt (C and Fortran)

Display error message with identifier and return to MATLAB prompt

C Syntax

#include "mex.h"

void mexErrMsgIdAndTxt(const char *errorid,

const char *errormsg, ...);

Fortran Syntax

#include "fintrf.h"

subroutine mexErrMsgIdAndTxt(errorid, errormsg)

character*(*) errorid, errormsg

Arguments

erroridString containing a MATLAB® message identifier. For information on creating identifiers,

see MException.errormsgString to display, specified as const char*

in C or character*(*) in Fortran. In C, the function supports either UTF-8 or

local code page (LCP) encoding and the string can include conversion specifications, used by the

ANSI® C

printf function. The encoding for both the message text and the conversion

arguments must be the same....In C, any arguments used in the message. Each argument must

have a corresponding conversion specification. Refer to your C documentation

for printf conversion tables.

Description

The mexErrMsgIdAndTxt function writes an error message to the

MATLAB window. For more information, see the error function syntax statement using a message identifier. After the

error message prints, MATLAB terminates the MEX file and returns control to the MATLAB prompt.

Calling mexErrMsgIdAndTxt does not clear the MEX file from

memory. So, mexErrMsgIdAndTxt does not invoke the function

registered through mexAtExit.

If your application called mxCalloc or one of the

mxCreate* routines to allocate memory,

mexErrMsgIdAndTxt automatically frees the allocated

memory.

Note

If you get warnings when using mexErrMsgIdAndTxt, you might

have a memory management compatibility problem. For more information, see Memory Management Issues.

Remarks

In addition to the errorid and errormsg, the

mexErrMsgIdAndTxt function determines where the error occurred,

and displays the following information. For example, in the function

foo, mexErrMsgIdAndTxt displays:

Error using foo

If you compile your MEX file with the MinGW-w64 compiler, see the limitations with

exception handling topic in Troubleshooting and Limitations Compiling C/C++ MEX Files with MinGW-w64.

Examples

See these examples in

matlabroot/extern/examples/refbook:

Validate char Input

The following code snippet checks if input argument, prhs[0],

is a string. If not, the code displays a warning. If there is an error reading the

input string, the code displays an error message and terminates the MEX file.

char *buf;

int buflen;

// initialize variables

if (mxIsChar(prhs[0])) {

if (mxGetString(prhs[0], buf, buflen) == 0) {

mexPrintf("The input string is: %s\n", buf);

}

else {

mexErrMsgIdAndTxt("MyProg:ConvertString",

"Could not convert string data.");

// exit MEX file

}

}

else {

mexWarnMsgIdAndTxt("MyProg:InputString",

"Input should be a string to print properly.");

}

// continue with processing

Introduced before R2006a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值