Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing complete error stack while error handling

I have a matlab script that calls various other function. I am handling possible error in the following way

            try
                 matStart(MatObj);
             catch err
                 msgbox('Error in Processing Figures!','Error!','error','modal');
                 fprintf(2,err.message);
                 sprintf('\n');
                 display(err.message);
            end

as you can probably guess, this prints the error that caused the exception.But this only prints the very first function that caused the error. I want the whole error stack to be shown down to the last nested function that caused the error to occur. Can tis be done?

like image 471
Adnan Avatar asked Aug 14 '12 00:08

Adnan


People also ask

How do I get an error stack?

Use the console. trace() method to get the stack trace from an error. The console. trace() method outputs the stack trace and shows the call path taken to reach the point at which the method was called.

What does stack error mean?

A stack overflow is a runtime error that happens when a program runs out of memory in the call stack. The stack overflow generally signals a problem in resource provisioning and has to be fixed in order to allow the program to run and use memory properly.

What is stack trace error?

Stack trace error is a generic term frequently associated with long error messages. The stack trace information identifies where in the program the error occurs and is helpful to programmers. For users, the long stack track information may not be very useful for troubleshooting web errors.

How can I check my browser stack trace?

You can easily see the stack trace in JavaScript by adding the following into your code: console. trace(); And you'll get an outputted stack trace.


2 Answers

Yes, the function you're looking for is "getReport". You'll want the 'extended' report.

Using getReport, your code would look like this

        try
             matStart(MatObj);
         catch err
             msgbox('Error in Processing Figures!','Error!','error','modal');
             disp(getReport(err,'extended'));
        end

This will display the same information as an uncaught exception in matlab that prints the full stack trace, though of course the text won't be red.

like image 133
lawinslow Avatar answered Sep 27 '22 02:09

lawinslow


Following on from @thewopr's answer, you can have the text printed in red if you wish by printing the error stack to the 'standard error' output stream, like so:

...
fprintf(2, '%s\n', getReport(err, 'extended'));
...
like image 39
Edric Avatar answered Sep 25 '22 02:09

Edric