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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:29:54+00:00 2026-06-07T10:29:54+00:00

I have a problem with the following try and catch code in MATLAB: fonster=”;

  • 0

I have a problem with the following try and catch code in MATLAB:

fonster='';
while ~(~isempty(fonster) && isnumeric(fonster) && isreal(fonster) && isfinite(fonster) && (fonster == fix(fonster)) && (fonster > 0))
    try
        fonster = input('Välj ett heltal till fönsterplatsen du vill lägga grafen i: ');
    catch
        disp('Du måste mata in ett heltal');
    end
end

It never seems to enter the catch part of the code when entering an invalid input as a string to the input function. Instead it just runs the input all over again and ignores my output message. The wierd part is that I’m using a disp within a catch in another place in my code but this time it just doesn’t work.

Here are some running examples:

Input without the try and catch statements:

Välj den fönsterplats du vill lägga grafen i: o
Error using input
Undefined function or variable 'o'.

Error in skapaPlot (line 11)
    fonster = input('Välj den fönsterplats du vill lägga grafen i:
    ');

Error in mainMeny (line 17)
            plot_handles = skapaPlot(plot_handles);

Välj den fönsterplats du vill lägga grafen i:

With try and catch:

Välj ett heltal till fönsterplatsen du vill lägga grafen i: f
Välj ett heltal till fönsterplatsen du vill lägga grafen i: d
Välj ett heltal till fönsterplatsen du vill lägga grafen i: s
Välj ett heltal till fönsterplatsen du vill lägga grafen i: 

Why doesn’t it display the disp part?!

  • 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-07T10:29:55+00:00Added an answer on June 7, 2026 at 10:29 am

    Matlab’s input expression evaluator will handle any exceptions raised during input, and immediately redisplay the prompt, and the exception will get cleared. So your catch handler never gets to see any exceptions. If you want to manage things yourself, use instead input(…, ‘s’), which returns the raw string. You can then perform your evaluation using ‘eval()’:

    try
        inputstring = input('Välj ett heltal till fönsterplatsen du vill lägga grafen i: ', 's');
        fonster = eval(inputstring);
    catch
        disp('Du måste mata in ett heltal');
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: try { res = new Utils(ubc_context).new DownloadCalendarTask().execute().get(); } catch
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
Never thought I'd have this problem :) The following snippet of code works in
i'm new to jquery .I have problem in the following code .I saved it
Good Morning All, I have code similar to the following try{ using(var tx =
I have this problem, my code doesn't work when i try to find eyes
Hello everybody I have a problem with exception. The following code block do this
I have a problem with the following code fragment. It's intended to handle events
Good day to all. I have a problem with the following code: textBox.addEventListener(KeyboardEvent.KEY_DOWN,handler); function
i have a problem with deltaTime ive been using. My Code is the following:

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.