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

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

Komentarze do niniejszej Instrukcji

Brak uwag