MATLAB BUILDER JA 2 Betriebsanweisung Seite 66

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 292
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 65
3 Programming
public Object[] myprimes(int nargout, Object n) throws MWException
{
(implementation omitted)
}
Any method that calls myprimes must do one of two things:
Catch and handle the
MWException.
Allow the calling program to catch it.
The following two sections prov ide ex amples of each.
Code Fragment: Handling an Exception in the Called Function
The getprimes example shown here uses the first of these methods. This
method handles the exception itself, and does not need to include a
throws
clause at the start.
public double[] getprimes(int n)
{
myclass cls = null;
Object[] y = null;
try
{
cls = new myclass();
y = cls.myprimes(1, new Double((double)n));
return (double[])((MWArray)y[0]).getData();
}
/* Catches the exception thrown by myprimes */
catch (MWException e)
{
System.out.println("Exception: " + e.toString());
return new double[0];
}
finally
{
MWArray.disposeArray(y);
3-20
Seitenansicht 65
1 2 ... 61 62 63 64 65 66 67 68 69 70 71 ... 291 292

Kommentare zu diesen Handbüchern

Keine Kommentare