lasterror (stack.name)

View: New views
12 Messages — Rating Filter:   Alert me  

lasterror (stack.name)

by gOS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've noticed that when I run a mex file (foo.mex) and have it call mexErrMsgIdAndTxt('component:mnemonic','message'), that I am receiving unexpected values from last error.

For the sake of this example, assume moo.m calls foo.

function moo

  output = foo(input)
  le = lasterror

end
=========================

le =
{
   message = error: foo: message
   identifier = component:mnemonic
   stack =
   {
      file = C:\file\blah\...\moo.m
      name = moo
      line = 3
      column = 8
   }
}

===============

As you can see, foo is referenced in the error message, but does not get credit in the stack. Instead, moo is determined to be the offending function. I understand line & column would not have values when referencing a mex function, but it makes writing a function like handleError() a little more difficult if I can't trust the stack to always return the correct information or if I have to parse message to find out what the actual function was that crashed.

I suppose, its possible to program all the desired information into the identifier when using mex files, but I still wanted to check if this was the expected behavior.

Re: lasterror (stack.name)

by gOS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Someone asked me via mail how I got around this and the answer is this, though the workaround solution that I have is not the answer I seek to my question:

When a mex function uses mexErrMsgIdAndTxt, the two inputs are 'id' and 'msg'

'msg' is prepended with 'error: foo: ' to become 'error: foo: message'

To extract the name of the failing function I've used the following code:

===========================

le = lasterror;
msg = le.message;
colonPos = strfind(msg,':')
failingFunc = msg((colonPos(1)+2):colonPos(2)-1)

===========================

I added 'MEX' as a mnemonic to the identifier so that it became: 'component:MEX:mnemonic'

Then used the conditional:

if(sum(strfind(le.identifier,'MEX')))

to determine whether I needed to handle the error reporting differently. Its a hastle, makes code uglier, etc., but it works and I don't see another way around this.

gOS wrote:
I've noticed that when I run a mex file (foo.mex) and have it call mexErrMsgIdAndTxt('component:mnemonic','message'), that I am receiving unexpected values from last error.

For the sake of this example, assume moo.m calls foo.

function moo

  output = foo(input)
  le = lasterror

end
=========================

le =
{
   message = error: foo: message
   identifier = component:mnemonic
   stack =
   {
      file = C:\file\blah\...\moo.m
      name = moo
      line = 3
      column = 8
   }
}

===============

As you can see, foo is referenced in the error message, but does not get credit in the stack. Instead, moo is determined to be the offending function. I understand line & column would not have values when referencing a mex function, but it makes writing a function like handleError() a little more difficult if I can't trust the stack to always return the correct information or if I have to parse message to find out what the actual function was that crashed.

I suppose, its possible to program all the desired information into the identifier when using mex files, but I still wanted to check if this was the expected behavior.

lasterror (stack.name)

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On  4-Jun-2008, gOS wrote:

|
| I've noticed that when I run a mex file (foo.mex) and have it call
| mexErrMsgIdAndTxt('component:mnemonic','message'), that I am receiving
| unexpected values from last error.
|
| For the sake of this example, assume moo.m calls foo.
|
| function moo
|
|   output = foo(input)
|   le = lasterror
|
| end
| =========================
|
| le =
| {
|    message = error: foo: message
|    identifier = component:mnemonic
|    stack =
|    {
|       file = C:\file\blah\...\moo.m
|       name = moo
|       line = 3
|       column = 8
|    }
| }
|
| ===============
|
| As you can see, foo is referenced in the error message, but does not get
| credit in the stack. Instead, moo is determined to be the offending
| function. I understand line & column would not have values when referencing
| a mex function, but it makes writing a function like handleError() a little
| more difficult if I can't trust the stack to always return the correct
| information or if I have to parse message to find out what the actual
| function was that crashed.
|
| I suppose, its possible to program all the desired information into the
| identifier when using mex files, but I still wanted to check if this was the
| expected behavior.

What does Matlab do?

If you think you've found a bug, then please submit a complete bug
report to the bug@... list, including the code necessary to
reproduce the error, so we don't have to guess or duplicate that
effort.

jwe
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: lasterror (stack.name)

by gOS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John W. Eaton wrote:
What does Matlab do?

If you think you've found a bug, then please submit a complete bug
report to the bug@octave.org list, including the code necessary to
reproduce the error, so we don't have to guess or duplicate that
effort.

jwe
I have no idea what Matlab does in this case so I have no idea whether its a bug or not. I'm just trying to find out if this is the expected behavour or if its likely that in the future my approach to solve this problem won't work because the strings are created differently, etc.

I'm more worried about relying on a string supplied by octave that could change with the next release than I am about the actual behavior I see now. Though it would be nice to know what matlab does, if anyone does know please reply.

Re: lasterror (stack.name)

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On  4-Jun-2008, gOS wrote:

| I'm more worried about relying on a string supplied by octave that could
| change with the next release than I am about the actual behavior I see now.
| Though it would be nice to know what matlab does, if anyone does know please
| reply.

How about making that easy, by posting a *complete* example that
someone could easily run?

jwe
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: lasterror (stack.name)

by gOS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John W. Eaton wrote:
How about making that easy, by posting a *complete* example that
someone could easily run?

jwe
Whoever does this will have to compile the mex file themselves.

As per request, here is an example:

moo.m

function moo
  try
    foo
  catch
    lasterror
  end
end
 
==============================================================================
 
foo.c

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  mexErrMsgIdAndTxt("component:mnemonic","This is an error message.");
}

I have no idea what Matlab does in this case so I have no idea whether its a bug or not. I'm just trying to find out if this is the expected behavour or if its likely that in the future my approach to solve this problem won't work because the strings are created differently, etc.

I'm more worried about relying on a string supplied by octave that could change with the next release than I am about the actual behavior I see now. Though it would be nice to know what matlab does, if anyone does know please reply.


Re: lasterror (stack.name)

by Søren Hauberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ons, 04 06 2008 kl. 09:25 -0700, skrev gOS:
> foo.c
>
> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
> {
>   mexErrMsgIdAndTxt("component:mnemonic","This is an error message.");
> }

I tried compiling this in Matlab 7.4.0.129 (R2007a) using 'mex foo.c',
and I got:

foo.c:1: error: expected declaration specifiers or '...' before
'mxArray'
foo.c:1: error: expected ';', ',' or ')' before '*' token

    mex: compile of 'foo.c' failed.

??? Error using ==> mex at 206
Unable to complete successfully.

So, either you need to provide instructions on how to compile this, or
you need to check that the code you sent actually is compilable.

Søren

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: lasterror (stack.name)

by gOS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

foo.c (forgot the include statement). Compiles with octave mex compiler.:

#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  mexErrMsgIdAndTxt("component:mnemonic","This is an error message.");
}


Søren Hauberg wrote:
ons, 04 06 2008 kl. 09:25 -0700, skrev gOS:
> foo.c
>
> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
> {
>   mexErrMsgIdAndTxt("component:mnemonic","This is an error message.");
> }

I tried compiling this in Matlab 7.4.0.129 (R2007a) using 'mex foo.c',
and I got:

foo.c:1: error: expected declaration specifiers or '...' before
'mxArray'
foo.c:1: error: expected ';', ',' or ')' before '*' token

    mex: compile of 'foo.c' failed.

??? Error using ==> mex at 206
Unable to complete successfully.

So, either you need to provide instructions on how to compile this, or
you need to check that the code you sent actually is compilable.

Søren

_______________________________________________
Help-octave mailing list
Help-octave@octave.org
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: lasterror (stack.name)

by Søren Hauberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Then I get

>> moo        

ans =

       message: 'This is an error message.'
    identifier: 'component:mnemonic'
         stack: [1x1 struct]


Hope it helps,
Søren

tor, 05 06 2008 kl. 06:39 -0700, skrev gOS:

> foo.c (forgot the include statement). Compiles with octave mex compiler.:
>
> #include "mex.h"
>
> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
> {
>   mexErrMsgIdAndTxt("component:mnemonic","This is an error message.");
> }
>
>
>
> Søren Hauberg wrote:
> >
> > ons, 04 06 2008 kl. 09:25 -0700, skrev gOS:
> >> foo.c
> >>
> >> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray
> >> *prhs[])
> >> {
> >>   mexErrMsgIdAndTxt("component:mnemonic","This is an error message.");
> >> }
> >
> > I tried compiling this in Matlab 7.4.0.129 (R2007a) using 'mex foo.c',
> > and I got:
> >
> > foo.c:1: error: expected declaration specifiers or '...' before
> > 'mxArray'
> > foo.c:1: error: expected ';', ',' or ')' before '*' token
> >
> >     mex: compile of 'foo.c' failed.
> >
> > ??? Error using ==> mex at 206
> > Unable to complete successfully.
> >
> > So, either you need to provide instructions on how to compile this, or
> > you need to check that the code you sent actually is compilable.
> >
> > Søren
> >
> > _______________________________________________
> > Help-octave mailing list
> > Help-octave@...
> > https://www.cae.wisc.edu/mailman/listinfo/help-octave
> >
> >
>

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: lasterror (stack.name)

by gOS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well it is certainly slightly different as message would have been 'error: moo: This is an error message'

The identifier works, but I'm interested in what the stack actually contains if anything. I'm assuming its a 1x1 empty array

Søren Hauberg wrote:
Then I get

>> moo        

ans =

       message: 'This is an error message.'
    identifier: 'component:mnemonic'
         stack: [1x1 struct]


Hope it helps,
Søren

tor, 05 06 2008 kl. 06:39 -0700, skrev gOS:
> foo.c (forgot the include statement). Compiles with octave mex compiler.:
>
> #include "mex.h"
>
> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
> {
>   mexErrMsgIdAndTxt("component:mnemonic","This is an error message.");
> }
>
>
>
> Søren Hauberg wrote:
> >
> > ons, 04 06 2008 kl. 09:25 -0700, skrev gOS:
> >> foo.c
> >>
> >> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray
> >> *prhs[])
> >> {
> >>   mexErrMsgIdAndTxt("component:mnemonic","This is an error message.");
> >> }
> >
> > I tried compiling this in Matlab 7.4.0.129 (R2007a) using 'mex foo.c',
> > and I got:
> >
> > foo.c:1: error: expected declaration specifiers or '...' before
> > 'mxArray'
> > foo.c:1: error: expected ';', ',' or ')' before '*' token
> >
> >     mex: compile of 'foo.c' failed.
> >
> > ??? Error using ==> mex at 206
> > Unable to complete successfully.
> >
> > So, either you need to provide instructions on how to compile this, or
> > you need to check that the code you sent actually is compilable.
> >
> > Søren
> >
> > _______________________________________________
> > Help-octave mailing list
> > Help-octave@octave.org
> > https://www.cae.wisc.edu/mailman/listinfo/help-octave
> >
> >
>

_______________________________________________
Help-octave mailing list
Help-octave@octave.org
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: lasterror (stack.name)

by Søren Hauberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

man, 09 06 2008 kl. 06:06 -0700, skrev gOS:
> The identifier works, but I'm interested in what the stack actually contains
> if anything. I'm assuming its a 1x1 empty array

The stack is

0x1 struct array with fields:
    file
    name
    line

Søren

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: lasterror (stack.name)

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On  9-Jun-2008, Søren Hauberg wrote:

| man, 09 06 2008 kl. 06:06 -0700, skrev gOS:
| > The identifier works, but I'm interested in what the stack actually contains
| > if anything. I'm assuming its a 1x1 empty array
|
| The stack is
|
| 0x1 struct array with fields:
|     file
|     name
|     line

I don't think it should be empty.  I think I've fixed this in the
current sources to be compatible with the Matlab behavior.

jwe

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave