catch.ME returns incorrect line number for error
Show older comments
hi team
I have a script to download stock data and then do some analysis. The entire script is working fine except one little issue. I have try-catch function in my script to help me continur with stock analysis when error occurs. However when I use fprintf(ME.stack(1).line) to tell me the error location (line number) it return completely incorrect line numbers. My script has the following:
%% - to break the script in blocks for ease of use
... - to break codes in multiple lines for better readability
multiple For, If loops.
Due to sensitive info I have removed my codes but have created a structure of my script and attached here. If anyone can please help me understand why catch.ME returns incorrect line number it would be great.
Within try catch block - My codes has only two lines within try and catch block that needs try and catch (i.e., try, catch error and skip that iteration), other codes within the block just need to get skipped when error occurs. Is there a way in try catch function that we can tell what lines to apply try and catch and for the rest of the codes it throws an error and stop?
Summary - Try catch is working fine, doing what it needs to do except returning correct line number where error occured. I need help with this please.
My code has Me.stack(1).line, I noticed on matlab Q&A forum someone mentioning using Me.stack(end).line. Does this make any difference?
Regards
Amit
2 Comments
Walter Roberson
on 23 Feb 2025
Is it possible that your script is LiveScript ?
Amit Patel
on 23 Feb 2025
Accepted Answer
More Answers (0)
Categories
Find more on Programming Utilities in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!