addCause
예외의 추가적인 원인 기록
설명
은 기존 baseException
= addCause(baseException
,causeException
)MException
객체인 baseException
의 cause
속성에 causeException
을 추가(Append)하여 baseException을 수정합니다. try/catch
문에서 결과 예외를 포착하면, 예외가 추가(Append)된 모든 원인 기록과 함께, 오류 진단에 사용할 수 있는 기본 예외가 만들어집니다.
예제
예외에 원인 추가
배열을 만들고, 논리형 배열을 사용하여 배열의 요소를 참조합니다.
A = [13 42; 7 20]; idx = [1 0 1; 0 1 0];
오류에 대한 일반 정보를 제공하는 예외를 만듭니다. 인덱스 배열을 테스트하고 실패 원인에 대한 자세한 정보와 함께 예외를 추가합니다.
try A(idx); catch errID = 'MYFUN:BadIndex'; msg = 'Unable to index into array.'; baseException = MException(errID,msg); try assert(islogical(idx),'MYFUN:notLogical',... 'Indexing array is not logical.') catch causeException baseException = addCause(baseException,causeException); end if any(size(idx) > size(A)) errID = 'MYFUN:incorrectSize'; msg = 'Indexing array is too large.'; causeException2 = MException(errID,msg); baseException = addCause(baseException,causeException2); end throw(baseException) end
Unable to index into array.
Caused by:
Indexing array is not logical.
Indexing array is too large.
baseException
객체를 검토합니다.
baseException
baseException = MException with properties: identifier: 'MYFUN:BadIndex' message: 'Unable to index into array.' cause: {2x1 cell} stack: [0x1 struct]
cause
속성의 값은 2x1
셀형 배열입니다.
예외의 첫 번째 원인을 검토합니다.
baseException.cause{1}
ans = MException with properties: identifier: 'MYFUN:notLogical' message: 'Indexing array is not logical.' cause: {0x1 cell} stack: [0x1 struct]
예외의 두 번째 원인을 검토합니다.
baseException.cause{2}
ans = MException with properties: identifier: 'MYFUN:incorrectSize' message: 'Indexing array is too large.' cause: {} stack: [0x1 struct]
입력 인수
baseException
— 주 예외
MException
객체
오류의 주 원인과 위치를 포함하는 주 예외로, MException
객체로 지정됩니다.
causeException
— 관련 예외
MException
객체
baseException
과 관련된 오류의 원인과 위치를 포함하는 관련 예외로, MException
객체로 지정됩니다.
버전 내역
R2007b에 개발됨
참고 항목
throw
| rethrow
| throwAsCaller
| MException.last
| assert
| try, catch
| error
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)