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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:46:49+00:00 2026-06-10T07:46:49+00:00

What is the correct syntax for catching an exception in GNU Octave? I have

  • 0

What is the correct syntax for catching an exception in GNU Octave? I have a line that fails if there is no file present:

mymatrix = load("input.txt");

If input.txt has some bad rows in it, octave barfs with this sort of thing:

error: load: unable to extract matrix size from file `input.txt'
error: called from:
error: /home/el/loadData.m at line 93, column 20
error: main at line 37, column 86
error: /home/el/main.m at line 132, column 5

I’d like to use a try/catch block in Octave, what is the proper syntax?

I want to be able to report cleanly and accurately to the user that something is wrong with the input file (missing, incorrectly configured columns, too many columns, bad characters, etc), and recover. Not just spew cryptic errors and halt. what is the best way to do that?

  • 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-10T07:46:50+00:00Added an answer on June 10, 2026 at 7:46 am

    First, read the official documentation on Octave try/catch

    and general exception handling

    Here is the correct syntax to catch an exception in GNU Octave:

    %make sure foobar.txt does not exist.
    %Put this code in mytest.m.
    
    try
      mymatrix = load("foobar.txt");   %this line throws an exception because 
                                       %foobar does not exist.
    catch
      printf ("Unable to load file: %s\n", lasterr)
    end
    
    
    disp(mymatrix)  %The program will reach this line when the load command
    %fails due to missing input file.  The octave catch block eats the 
    %exception and ignores it.
    

    When you run the above code, this prints:

    Unable to load file: load: unable to find file foobar.txt
    

    Then the exception thrown from the load file is ignored, since disp(mymatrix) was not defined in the try block, an additional exception halts the program because mymatrix is not defined.

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

Sidebar

Related Questions

I have the following method that I can't figure out correct syntax to call:
What is the correct jQuery syntax to only select certain file types? e.g. $(#fragment-1
What would be the correct syntax and join (if any) of a subquery that
Is this the correct syntax for passing a file pointer by reference? Function call:
What's the correct syntax to search a .txt file for a keyword in JavaScript?
What is the correct syntax to create objects in javascript that will work across
What is the correct syntax for including an external js and external CSS file
I would like find the correct syntax for the SET line: Doctrine_Query::create() ->update('Media m')
What is the correct syntax for adding an external reference to a JavaScript file
What is the correct syntax in MongoDB to return all queries that meet the

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.