Home MATLAB issue with Exception Handling
Reply: 0

MATLAB issue with Exception Handling

user861
1#
user861 Published in May 26, 2018, 11:38 pm

I am trying to handle exceptions gracefully such that when a user enters a character, when a number is expected, he is notified with a custom warning/message.

I know that the try, catch has the following syntax:

try
   statements
catch exception
   statements
end

I have been trying something like this, to no avail:

number = input('Enter number'); 
try
    assert(isnumeric(number));
catch ME
    warning('NOT A NUMBER');
end

I do not understand why the above code fails since assert if it is false, displays the error message 'Assertion Failed'.

I know that using try and catch is a bit of a sledgehammer approach, but I would like to understand how to implement the above functionality. Any tips would be appreciated.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312734 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO