- We cannot modify the identifier of an existing "MException”, as the “identifier” property is a read-only property. Its value can only be assigned once whilst the creation of “MException” object. If you want to change the identifier, you can catch the thrown exception and create an exception of your own, like the code you have shared.
- You cannot directly modify or copy the stack to a new exception because it is a read-only property. However, you can create a new exception and use the “addCause” method to add the original exception as the cause, and you can access the stack trace via “new_exception.cause{1}.stack” , just like the code in the end of this answer.
- As mentioned, the stack trace is part of the original exception, and you cannot directly assign it to the new exception’s stack property. However, by adding the original exception as the cause, the new exception will have access to the original exception’s stack trace, which can be accessed and stored to a different variable.
- “MException” class: www.mathworks.com/help/matlab/ref/mexception.html
- “throw” function: www.mathworks.com/help/matlab/ref/mexception.throw.html
- “addClause” function: www.mathworks.com/help/matlab/ref/mexception.addcause.html
- “error” function: www.mathworks.com/help/matlab/ref/error.html