MATLAB BUILDER JA 2 Podręcznik Użytkownika Strona 66

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 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
Przeglądanie stron 65
1 2 ... 61 62 63 64 65 66 67 68 69 70 71 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag