<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264884</link>
    <title>MATLAB Central Newsreader - how to catch native C exception from Matlab user-defined function?</title>
    <description>Feed for thread: how to catch native C exception from Matlab user-defined function?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 03 Nov 2009 22:15:04 -0500</pubDate>
      <title>how to catch native C exception from Matlab user-defined function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264884#691862</link>
      <author>Ian Bell</author>
      <description>Assume a user-defined Matlab function (e.g. MyFunction) executes 'calllib' to call a function in a native C DLL and that the C function throws an exception (e.g. std::exception).   Can the user-defined Matlab function use a MException try/catch block to catch the native C exception?   If not, what is the recommended way to catch an exception thrown from within a native C DLL?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
Ian</description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 23:03:38 -0500</pubDate>
      <title>Re: how to catch native C exception from Matlab user-defined function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264884#691873</link>
      <author>Philip Borghesani</author>
      <description>There is no way to catch a C++ exception in MATLAB from a function called with calllib.  Note that such a function is not a C &lt;br&gt;
function it is a C++ function.  The best solution is to code a wrapper dll in c++ to catch the exceptions and return error codes or &lt;br&gt;
make calls to mexErrMsgIdAndTxt.  The wrapper dll can be loadable with loadlibrary or it can be a MEX function.&lt;br&gt;
&lt;br&gt;
Most dlls that allow exceptions to be thrown from their functions have strict compiler compatibility requirements because of the &lt;br&gt;
different ways compilers treat exceptions so you may need to build the helper dll with the same compiler that was used to build the &lt;br&gt;
dll you are calling.&lt;br&gt;
&lt;br&gt;
Phil&lt;br&gt;
&lt;br&gt;
&quot;Ian Bell&quot; &amp;lt;ibell@instepsystems.com&amp;gt; wrote in message news:hcqa18$m8c$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Assume a user-defined Matlab function (e.g. MyFunction) executes 'calllib' to call a function in a native C DLL and that the C &lt;br&gt;
&amp;gt; function throws an exception (e.g. std::exception).   Can the user-defined Matlab function use a MException try/catch block to &lt;br&gt;
&amp;gt; catch the native C exception?   If not, what is the recommended way to catch an exception thrown from within a native C DLL?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Ian </description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 23:22:03 -0500</pubDate>
      <title>Re: how to catch native C exception from Matlab user-defined function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264884#691876</link>
      <author>Ian Bell</author>
      <description>Thanks Philip</description>
    </item>
  </channel>
</rss>

