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

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 67
3 Programming
cls.dispose();
}
}
Handling Unchecked Exceptions
Several types of unchecked e xceptio ns can also occur during the course of
execution. Unchecked exceptions are Java exceptions that do not need to be
explicitly declared with a
throws clause. The MWArray API classes all throw
unchecked exceptions.
All unchecked exceptions thrown by
MWArray and its subclasses are s ubclasses
of
java.lang.RuntimeException. The following e xceptions can be thrown
by
MWArray:
java.lang.RuntimeException
java.lang.ArrayStoreException
java.lang.NullPointerException
java.lang.IndexOutOfBoundsException
java.lang.NegativeArraySizeException
This list re pre sents the most likely exceptions. Others might be added in the
future. For information on the exceptions that can occur for each method of
MWArray and its subclasses, see Using MWA rray Classe s.
Code Fragment: Catching General Exceptions
You can easily rewrite the getprimes example to catch any exception that can
occur during the method call and data conversion. Just change the
catch
clause to catch a general java.lang.Exception.
public double[] getprimes(int n)
{
myclass cls = null;
Object[] y = null;
try
{
cls = new myclass();
3-22
Przeglądanie stron 67
1 2 ... 63 64 65 66 67 68 69 70 71 72 73 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag