help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using error() in oct-files


From: John W. Eaton
Subject: using error() in oct-files
Date: Tue, 13 Jun 2006 10:21:36 -0400

On 13-Jun-2006, address@hidden wrote:

| I have a question regarding the use of error() in a C++ oct-file. When 
| called, error() just displays the error message but does not terminate the 
| oct-file and return control to the octave prompt.

That's the way it was designed to work.

| This behaviour is 
| different to the behaviour of mexErrMsgTxt.

It's not the same function and Octave is not Matlab, so why should it
behave the same way?

| I order to leave the oct-file, 
| I have to return an octave_value.

Yes.

| However this doesn't seem to make sense 
| to me, as the return value can't be accessed at the octave prompt when an 
| error has occured in the oct-file.

If an error has occurred, why should the Octave interpreter assume
that a function would return a valid value?

| What is the intention behind this 
| behaviour of error().

When you call error, it also sets a global error value called
"error_state" that you can access.  If error_state is non-zero, then
an error has occurred (for more detail, see the definition of this
variable in src/error.cc.  The Octave interpreter checks the value of
error_state after fuction calls to decide whether to continue normal
processing or clean up and return control the the prompt.  All the
code to handle this was done in the dark ages before C++ had exception
handling.  Yes, I could have used setjmp/longjmp, but that's not what
I decided to do.  Changing the error function to throw an exception
so it would behave much like the have the error function in the
scripting language might be possible, but it is not a high priority
for me.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]