ferror
Returns the error message and code of the last file operation.
Category: Data Import and Analysis > Data Import and Export
Syntax
msg = ferror(fid)
Returns the message text.
[msg, errnum] = ferror(fid)
Also returns a numeric error code.
Description
ferror reports the state of the file after the most recent input or output call. For a file that has been used without problems the message is empty and the code is 0. It is most useful right after a read or write that appeared to fail.
Input arguments
fid- File identifier from
fopen.
Output arguments
msg- Error message, empty when there is no error.
errnum- Error code,
0when there is no error.
Example
A healthy file
fid = fopen('e.txt', 'w');
fprintf(fid, 'x');
[msg, code] = ferror(fid)
fclose(fid);
Output
msg = 0×0 empty char array
code = 0