I was trying to use the warning()
function with a warning message. When I try warning('random message')
it works perfectly fine. But if I change the string to error
instead, I get an error saying it doesn't have enough input arguments:
warning('error')
Error using warning
Not enough input arguments.
Is there something special about the word error
that prevents me from using it as a message?
I am using 2014b
.
Yes, the 'error'
flag is a special undocumented option that requires an additional input (a message identifier). It is used for trapping/catching warnings as errors. See this Undocumented Matlab post and this MathWorks Newsgroup posting.
This issue can be replicated in R2015a as well. Perhaps this useful option should be documented or maybe warning('error')
with no message identifier should just work as expected. You might consider filing a service request with The MathWorks.
However, it's probably a good habit to use the the two-input form of warning
(and error
) with the initial message ID. For example:
warning('MyFunction1:MyWarningName1','error')
or
warning('MyLibrary:MyFunction2:MyWarningName2','error')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With