MATLAB Programming
MATLAB Programming MATLAB Programming
8 Error Handling matrixMultiply(A, C) ** Both arguments must be double matrices Regenerating an Error Use the rethrow function to regenerate an error that has previously been thrown.Youmightwanttodothisfromthecatch part of a try-catch block, for example, after performing some required cleanup tasks following an error. This is the general method used to rethrow an error in a try-catch block: try - do_something - catch - do_cleanup - rethrow(lasterror) end rethrow generates an error based on the MATLAB structure you provide as an input argument. The input structure must have at least one of the message, identifier, andstack fields. Field Name message identifier stack Description Character array containing the text of the error message. Character array containing the message identifier of the error message. If the last error issued by MATLAB had no message identifier, then the identifier field is an empty character array. Structure providing information on the location of the error. The structure has fields file, name, and line, and is the same as the structure returned by the dbstack function. If lasterror returns no stack information, stack is a 0-by-1 structure having the same three fields. If you simply want to regenerate the last error that occurred, the lasterror function returns a structure that can then be passed directly to rethrow. 8-8
Handling and Recovering from an Error Note lasterror is not the same as lasterr. Thelasterror function returns a structure array that contains the message string, message identifier, and stack information for the last error, and might contain more information in future versions of MATLAB. The lasterr function returns one or two character arrays that contain only the message string and identifier. 8-9
- Page 592 and 593: 7 Working with Scientific Data Form
- Page 594 and 595: 7 Working with Scientific Data Form
- Page 596 and 597: 7 Working with Scientific Data Form
- Page 598 and 599: 7 Working with Scientific Data Form
- Page 600 and 601: 7 Working with Scientific Data Form
- Page 602 and 603: 7 Working with Scientific Data Form
- Page 604 and 605: 7 Working with Scientific Data Form
- Page 606 and 607: 7 Working with Scientific Data Form
- Page 608 and 609: 7 Working with Scientific Data Form
- Page 610 and 611: 7 Working with Scientific Data Form
- Page 612 and 613: 7 Working with Scientific Data Form
- Page 614 and 615: 7 Working with Scientific Data Form
- Page 616 and 617: 7 Working with Scientific Data Form
- Page 618 and 619: 7 Working with Scientific Data Form
- Page 620 and 621: 7 Working with Scientific Data Form
- Page 622 and 623: 7 Working with Scientific Data Form
- Page 624 and 625: 7 Working with Scientific Data Form
- Page 626 and 627: 7 Working with Scientific Data Form
- Page 628 and 629: 7 Working with Scientific Data Form
- Page 630 and 631: 7 Working with Scientific Data Form
- Page 632 and 633: 7 Working with Scientific Data Form
- Page 634 and 635: 7 Working with Scientific Data Form
- Page 636 and 637: 8 Error Handling Checking for Error
- Page 638 and 639: 8 Error Handling Handling and Recov
- Page 640 and 641: 8 Error Handling X = A * B catch di
- Page 644 and 645: 8 Error Handling Message Identifier
- Page 646 and 647: 8 Error Handling error('msg_id', 'e
- Page 648 and 649: 8 Error Handling Warnings Like erro
- Page 650 and 651: 8 Error Handling Warning Control Th
- Page 652 and 653: 8 Error Handling warnings by issuin
- Page 654 and 655: 8 Error Handling You must type the
- Page 656 and 657: 8 Error Handling s(2) ans = identif
- Page 658 and 659: 8 Error Handling end function f2(x)
- Page 660 and 661: 8 Error Handling Debugging Errors a
- Page 662 and 663: 9 Classes and Objects Classes and O
- Page 664 and 665: 9 Classes and Objects The diagram s
- Page 666 and 667: 9 Classes and Objects functions do
- Page 668 and 669: 9 Classes and Objects visible only
- Page 670 and 671: 9 Classes and Objects Class Method
- Page 672 and 673: 9 Classes and Objects Examples of C
- Page 674 and 675: 9 Classes and Objects not support p
- Page 676 and 677: 9 Classes and Objects overloaded me
- Page 678 and 679: 9 Classes and Objects A(1,2).name(3
- Page 680 and 681: 9 Classes and Objects Object Indexi
- Page 682 and 683: 9 Classes and Objects Converter Met
- Page 684 and 685: 9 Classes and Objects Operation M-F
- Page 686 and 687: 9 Classes and Objects Example — A
- Page 688 and 689: 9 Classes and Objects to the .c fie
- Page 690 and 691: 9 Classes and Objects end if d >= 2
Handling and Recovering from an Error<br />
Note lasterror is not the same as lasterr. Thelasterror function returns<br />
a structure array that contains the message string, message identifier, and<br />
stack information for the last error, and might contain more information<br />
in future versions of <strong>MATLAB</strong>. The lasterr function returns one or two<br />
character arrays that contain only the message string and identifier.<br />
8-9