Skip to content

Friendly Error Handling #11

Description

@dankessler

When something goes wrong in one of our scripts (e.g. a path specified doesn't exist, a file isn't the right format, etc), we want to catch it. If we don't, some downstream error (usually a matrix indexing error) will manifest, the user will get an error stack, and it won't be terribly interpretable.

Instead, we want to interrupt code right where the error happened, and ideally fix it for them, but failing that, stop execution, and give the user a friendly, informative error message, in addition to (or instead of) the error stack from matlab.

Several solutions have been proposed, after discussions with @sripada and @mangstad

Directly call error('Friendly Error Message')

This will give the user something handy, but this will unfortunately be printed at the top of the error trace, so it's possible the user will not notice it.

Put your top level function in a try catch block

Call an error when you actually get it, store the error stack, and store some useful friendly message. Then, up at your top level in the catch block, print out whatever you want the user to see (the friendly message, the error stack, or both).

Pop the error message as a dialog box

This will still print the regular error trace in the command window, but elevate the friendly message to a dialog box.

Print your friendly help, throw in a pause, and then call the error

This is very similar to directly calling the error, but makes it easier for the user to see the friendly message before the error trace is printed.


So, what do we think? Probably a good idea to choose one approach, adopt this as a standard, and document it in the Wiki

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions