How is a try catch block evaluated?

조회 수: 3 (최근 30일)
Patrik Ek
Patrik Ek 2014년 8월 22일
답변: Sean de Wolski 2014년 8월 22일
Hi, I wonder how a try-catch block is evaluated in matlab. In particular, is the try-catch block evaluated in runtime or compile time?
Also, is a try-catch block expensive?
If someone have a link to any documentation that would be much appreciated.
(Btw, I know that try-catch is not the best solution in most cases. Still I would like to know how it works, since I have used it in some code).

채택된 답변

Sean de Wolski
Sean de Wolski 2014년 8월 22일
My understanding is that the JIT does work with try/catch and that they do not affect performance as long as no exceptions are thrown. As soon as an exception is thrown, MATLAB deals with handling the exception, where performance is not as critical.

추가 답변 (1개)

Adam
Adam 2014년 8월 22일
It is evaluated at runtime. There is no compilation in Matlab so most things are done at runtime (excluding Mex compilation and similar).
I may be misunderstanding the question though. Even in C++ it is evaluated at runtime, because you don't know at compile time if something will throw an exception. If it would always throw an exception known at compile time then I'd imagine that's some bad coding design.
  댓글 수: 2
Patrik Ek
Patrik Ek 2014년 8월 22일
편집: Patrik Ek 2014년 8월 22일
Ok thanks for the answer. However matlab uses JIT compilation, so matlab of course compiles the code. Also, there are also possible to set up a try catch block in compile time. This is for example done in java. The JVM creates an exception object and then searches for a try in the stack. I am not sure if this is the way it is done in matlab, but it would be interesting to know.
Adam
Adam 2014년 8월 22일
Yes, true, I was rolling in the JIT compilation with runtime activity, but should have said there is no pre-compilation.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by