Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: mathlink error handling inside :Begin: - :End:

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109582] Re: mathlink error handling inside :Begin: - :End:
  • From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
  • Date: Thu, 6 May 2010 04:52:16 -0400 (EDT)

Hi,

bad idea. If you are interested, you could follow the way how
Mathematica registers an external MathLink function by looking inside
your .cpp File which was created from your .tm file.
There, your pattern and your arguments are used in the _definepattern  
function
which makes nothing more than calling the Kernel function  
"DefineExternal".
You can examine this function to see how Mathematica registers and  
calls your MathLink function.

But why don't you make it easy for yourself and just wrap your ML- 
func? Make a small
Mathematica-Module which

1. Checks the validity of your arguments
2. Does necessary precomputations
3. Calls your ML-func with always valid parameters
4. Returns results or error messages and catches errors from your ML- 
func

Cheers
Patrick




Am May 5, 2010 um 12:05 PM schrieb olanilsson:

> Hi,
>
> I have a small question about the mathlink-workings (I have gone
> through the documentation but can't seem to find an answer). I have an
> external mathlink/c++ program with the following signature:
>
> :Begin:
> :Function:      readexr
> :Pattern:       ReadEXR[ s_String ]
> :Arguments:     { AbsoluteFileName[s] }
> :ArgumentTypes: { String }
> :ReturnType:    Manual
> :End:
>
> :Evaluate: ReadEXR::usage = "ReadEXR[fn] reads an OpenEXR file and
> return its rgba channels."
>
> I thought I was clever when I used AbsoluteFileName, but I can't seem
> to detect any file-not-exist error. If I try to open a non-existent
> file a message is send to the kernel and printed in the frontend, but
> no error is found if I probe for MLError in my C++-code. Thus, my
> questions are:
>
> 1. Could I detect such an error already inside the Begin-End block,
> and if so abort execution at this point? Is this approach a good idea?
> 2. If not, how can (or should) I detect the error-state in the C++-
> code?
>
> Regards,
>
> Ola
>



  • Prev by Date: Re: Return intermediate reference using Hold*****?
  • Next by Date: Re: ComplexExpand and subscrips
  • Previous by thread: mathlink error handling inside :Begin: - :End:
  • Next by thread: Re: mathlink error handling inside :Begin: - :End: