Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7879311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:52:28+00:00 2026-06-03T03:52:28+00:00

In Matlab, there is, as far as I know, no good way to conditionally

  • 0

In Matlab, there is, as far as I know, no good way to conditionally catch exceptions (correct me if I’m wrong). The only way is to catch the exception, check the identifier, and rethrow the error if this particular error can not be handled. That’s acceptable though inconvenient. However, when I use Matlabs dbstop if error, I end up at the ME.rethrow() line. I’m then unable to dbup back to the place where the original error was caused.

function test_excc

try
    sub_test()
catch ME
    if strcmp(ME.identifier, 'test:notsobad')
        fprintf(1, 'Fine\n');
    else
        ME.rethrow();
    end
end

end

function sub_test
sub_sub_test();
end

function sub_sub_test()
if rand>0.5
    error('test:error', 'Noooo!');
else
    error('test:notsobad', 'That''OK');
end
end

Example usage:

>> test_excc()
Error using test_excc>sub_sub_test (line 21)
Noooo!

Error in test_excc>sub_test (line 16)
sub_sub_test();

Error in test_excc (line 4)
    sub_test()

9           ME.rethrow();
K>> dbstack
> In test_excc at 9

Although the Matlab desktop environment prints the entire stack trace back to sub_sub_test, the debugger does not give me the possibility to go up the stack trace and debug inside this function.

I am aware of dbstop if caught error. However, this will debug into any caught error, which may be many if software makes heavy use of exceptions. I only want to stop on uncaught errors, but I want to stop where the error is generated — not where it’s rethrown.

My question:

  • In Matlab, how do I conditionally catch an error (based on error identifier) and debug into the place where the error is originally thrown?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:52:29+00:00Added an answer on June 3, 2026 at 3:52 am

    I would guess that you cannot do this. As soon as execution enters the catch statement, dbstack will have to refer to that location inside the catch, so the information necessary to debug at the cause of the error is lost. ME.stack will tell you where the exception came from, but that isn’t sufficient to debug at that location.

    So I doubt you can solve the problem by doing something clever inside the catch. Looking at the documentation for catch, there also doesn’t seem to be a way to do a java-style catch (ExceptionType ME).

    There might be some hacky ways to solve this by using debug commands programmatically. For example, S = dbstatus saves the debug state and if there was a way to resume from a saved state, then you could attach this to the exception. But I can’t find any documented way to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if there is a way I could check from
Is there a way to make MATLAB remind a developer or warn a user
Is there any way to output/display information from a MATLAB program without an ending
Is there a way to establish a GPIB connection using MATLAB without the instrument
In matlab there is a way to find the values in one vector but
is there a way how to make Matlab open excel files directly in MS
I am new to Octave/Matlab so so far I know, you can apply matrix
Is there a Matlab function that returns the binary representation of a float number?
Is there an equivalent Matlab dot function in numpy? The dot function in Matlab:
Is there an efficient implementation of matlab's deconv in python? # Convolve z=conv(x, y)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.