MATLAB BUILDER JA 2 Guide de l'utilisateur Page 67

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 292
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 66
Handling Errors
if (cls != null)
cls.dispose();
}
}
Note that in this case, it is the programmer’s responsibility to return
something reasonable from the method in case of an error.
The
finally clause in the example contains code that executes after all
other processing in the
try block is executed. This code executes wh ether or
not an exception occurs or a control flow statement like
return or break
is executed. It is common practice to include any cleanup code that m ust
execute before leaving the function in a
finally block. The documentation
examples use
finally blocks in all the code samples to free native resources
that were allocated in the method.
For more information on free ing resources, se e “Managing Native Resources”
on page 3-25.
Code Fragment: Handling an Exception in the Calling Function
In this next example, the method that calls myprimes declares that it throws
an
MWException:
public double[] getprimes(int n) throws MWException
{
myclass cls = null;
Object[] y = null;
try
{
cls = new myclass();
y = cls.myprimes(1, new Double((double)n));
return (double[])((MWArray)y[0]).getData();
}
finally
{
MWArray.disposeArray(y);
if (cls != null)
3-21
Vue de la page 66
1 2 ... 62 63 64 65 66 67 68 69 70 71 72 ... 291 292

Commentaires sur ces manuels

Pas de commentaire