How can I make an exception in matlab?

I am writing code, and now I am performing some functions, but I am not writing them yet. I'm just doing an empty function that won't do anything. I would like to make an exception if the function is running so that I don't forget to write the function.

+4
source share
3 answers

The easiest way:

error('Some useful error message.') 

Matlab is happier, you assign an identifier to you error message, for example:

 error('toolsetname:other_identifying_information','Some useful error message here.') 

Identification information is reported with some error handling procedures, for example, try to trigger lasterror after each of the above calls.

+6
source

You can also use:

  throw(MException('Id:id','message')); 

There is a nice function for MException , it can be used as sprintf :

  throw(MException('Foo:FatalError',... 'First argument of Foo is %s, but it must be double',class(varargin{1}) )); 

As @edric correctly comments, this sprintf functionality can be a double sword. If you use some escape characters, this may not behave the way you want it to.

 throw(MException('Foo:FatalError',... 'I just want to add a \t, no tab!' )); 
+3
source

Have you read the MATLAB documentation for "Throwing an Exception" ?

+2
source

Source: https://habr.com/ru/post/1397206/


All Articles