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 9074969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:45:23+00:00 2026-06-16T18:45:23+00:00

Matlab crash when infinite recursion happens , as in the following code file: x.m

  • 0

Matlab crash when infinite recursion happens , as in the following code

file: x.m

function x
     y;
end

file: y.m

function y
     x;
end

file: script.m

x;

if the script script.m is executed matlab crash and it must be restarted.

even if I’ve used try-catch, it’s still crashing:

file: script.m

try
x;
catch
    error('stack-overflow');
end

Is there any way to handle such crash omitted from the infinite looping ?

  • 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-16T18:45:24+00:00Added an answer on June 16, 2026 at 6:45 pm

    As a quick trick, you can do

    global counter;
    global RecursionDepth;
    counter = 0;
    RecursionDepth = 1000;
    

    somewhere in beginning of your code, then you can do

    function IncrementCounterAndCheckDepth()
    
        global counter;
        global RecursionDepth;
        counter = counter+1;
        if counter > RecursionDepth
        error('stack-overflow');
    else
    disp(RecursionDepth);
        end;
        return;
    

    and insert it whenever necessary to check recursion. You can even add additional info/pass some arguments to it to improve your debugging, and once you are done with debugging, you can remove all globals and define IncrementCounterAndCheckDepth() to do nothing, so performance will not be affected, and for debugging it can be inserted in a lot of places without affecting performance. If you ever need to do additional debugging, you simply turn this function back on and modify is as required to track particular issue – you know it is everywhere in your code.

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

Sidebar

Related Questions

My matlab code does image processing, and I made matlab function which has 2
In MATLAB, when you click File -> New -> Function M-File, you get a
WARNING The code I provide in my question may crash matlab AND your machine!!!
In MATLAB, what does the following code do: [m, ~]=func_returning_matrix() What does the tilde
MATLAB has a very convenient syntax for getting half of a list: x(1:end/2) The
In MATLAB, why does the file have to be saved prior to running ?
Sometimes I start a MATLAB script and realize too late that it is going
MATLAB code exists to find the so-called minimum volume enclosing ellipsoid (e.g. here ,
In Matlab I have a class classdef myClass properties % some properties here... end
In MATLAB, the following syntax can be used to create 1-d matrix a and

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.