Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

Exception Handling

Capture and retrieve data on causes of errors

MATLAB Language Syntax

try, catch Execute statements and catch resulting errors

Classes

MException Capture error information

Functions

addCause Record additional causes of exception
getReport Get error message for exception
last Return last uncaught exception
rethrow Rethrow previously caught exception
throw Throw exception
throwAsCaller Throw exception as if occurs within calling function

Examples and How To

Capture Information About Exceptions

When a program throws an exception, information about what caused the error is captured in an MException object. If you catch the exception before your program aborts, you can access the information. You can also create MException objects that you use to throw exceptions in your code.

Throw an Exception

Detect conditions that keep your program from completing as expected or generate erroneous results, and then halt execution and throw an exception that reports the error.

Respond to an Exception

To handle an exception appropriately for a particular condition, capture information about the exception with a try/catch statement and then execute code to deal with the situation.

Concepts

Exception Handling in a MATLAB Application

It is a good programming practice to include error checking in your programs to ensure reliable operation under all conditions. You can decide how your programs respond to different types of errors.

Was this topic helpful?