Share via


Visual J# Exceptions 

Visual J# application developers must use the following two hierarchies of exceptions:

  • Java-language exceptions, which are derived from java.lang.Throwable. These exceptions fall into two categories:

    • Checked exceptions

      If a method results in a checked exception being thrown, the compiler issues an error, unless the code that calls the method has a try-catch block to catch the checked exception.

    • Run-time exceptions

      Derived from java.lang.RuntimeException. The compiler does not enforce any catching by the calling code.

  • .NET Framework exceptions, which are derived from Exception.

Many of the Java-language run-time exceptions have semantic equivalents in the .NET Framework. For example, java.lang.NullPointerException is similar to NullReferenceException.

When you catch a Java-language run-time exception in your source code, the Visual J# compiler ensures that the resulting executable code catches its .NET Framework equivalent as well.

Note

Handled run-time exceptions display in both the debugger and the error console as J# exceptions (as specified in the JDK 1.1.4 specification); unhandled run-time exceptions display in the debugger as .NET exceptions and in the error console as J# exceptions.

Java-language exceptions and their .NET Framework equivalents are listed in the following table.

Java-language exception .NET Framework exception

java.lang.ArithmeticException

ArithmeticException, DivideByZeroException, OverflowException

See the following topics for more information:

java.lang.ArrayIndexOutOfBoundsException

IndexOutOfRangeException

See Troubleshooting Exceptions: System.IndexOutOfRangeException.

java.lang.ArrayStoreException

ArrayTypeMismatchException

See Troubleshooting Exceptions: System.ArrayTypeMismatchException.

Java.lang.ClassCastException

See Troubleshooting Exceptions: System.InvalidCastException.

java.lang.IllegalAccessError

FieldAccessException, MethodAccessException

See the following topics for more information:

java.lang.IllegalArgumentException

ArgumentException, ArgumentNullException, ArgumentOutOfRangeException,

RankException

See the following topics for more information:

java.lang.IncompatibleClassChangeError

MissingMemberException

See Troubleshooting Exceptions: System.MissingMemberException.

java.lang.NoSuchFieldError

See Troubleshooting Exceptions: System.MissingFieldException.

java.lang.NoSuchMethodError

See Troubleshooting Exceptions: System.MissingMethodException

java.lang.NumberFormatException

See Troubleshooting Exceptions: System.FormatException.

java.lang.OutOfMemoryError

See Troubleshooting Exceptions: System.OutOfMemoryException

java.lang.SecurityException

See Troubleshooting Exceptions: System.Security.SecurityException.

java.lang.StackOverflowError

See Troubleshooting Exceptions: System.StackOverflowException.

java.lang.VerifyError

See Troubleshooting Exceptions: System.Security.VerificationException.

See Also

Reference

Visual J# Exception Hierarchies
Visual J# Exception Handling for the Debugger