0% found this document useful (0 votes)
60 views10 pages

Exception: 1.classnotfoundexception

The document defines 23 Java exception classes, describing what each exception is thrown for and how it relates to other exceptions. Some key exceptions discussed include ClassNotFoundException, thrown when a class cannot be found; NullPointerException, thrown when null is used where an object is required; and RemoteException, the common superclass for communication-related exceptions in remote method calls.

Uploaded by

Farzin Rahmanian
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views10 pages

Exception: 1.classnotfoundexception

The document defines 23 Java exception classes, describing what each exception is thrown for and how it relates to other exceptions. Some key exceptions discussed include ClassNotFoundException, thrown when a class cannot be found; NullPointerException, thrown when null is used where an object is required; and RemoteException, the common superclass for communication-related exceptions in remote method calls.

Uploaded by

Farzin Rahmanian
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

ClassNotFoundException
public class ClassNotFoundException
extends Exception
Thrown when an application tries to load in a class through its string name
using:

• The forName method in class Class.


• The findSystemClass method in class ClassLoader .
• The loadClass method in class ClassLoader.
But no definition for the class with the specified name could be found.

As of release 1.4, this exception has been retrofitted to conform to the general
purpose exception-chaining mechanism. The "optional exception that was
raised while loading the class" that may be provided at construction time and
accessed via the getException() method is now known as the cause, and may
be accessed via the Throwable.getCause() method, as well as the
aforementioned "legacy method.
2.IllegalAccessException
public class IllegalAccessException
extends Exception
An IllegalAccessException is thrown when an application tries to reflectively
create an instance (other than an array), set or get a field, or invoke a method,
but the currently executing method does not have access to the definition of
the specified class, field, method or constructor.

3.InstantiationException

public class InstantiationException


extends Exception
Thrown when an application tries to create an instance of a class using the
newInstance method in class, but the specified class object cannot be
instantiated because it is an interface or is an abstract class.

4.NullPointerException

public class NullPointerException


extends RuntimeException
Thrown when an application attempts to use null in a case where an object is
required. These include:

• Calling the instance method of a null object.


• Accessing or modifying the field of a null object.
• Taking the length of null as if it were an array.
• Accessing or modifying the slots of null as if it were an array.
• Throwing null as if it were a Throwable value.
Applications should throw instances of this class to indicate other illegal uses
of the null object.
5.NumberFormatException
public class NumberFormatException
extends IllegalArgumentException
Thrown to indicate that the application has attempted to convert a string to
one of the numeric types, but that the string does not have the appropriate
format.

6.RuntimeException

public class RuntimeException


extends Exception
RuntimeException is the superclass of those exceptions that can be thrown
during the normal operation of the Java Virtual Machine.

A method is not required to declare in its throws clause any subclasses of


RuntimeException that might be thrown during the execution of the method
but not caught.

7.StringIndexOutOfBoundsException

public class StringIndexOutOfBoundsException


extends IndexOutOfBoundsException
Thrown by String methods to indicate that an index is either negative or
greater than the size of the string. For some methods such as the charAt
method, this exception also is thrown when the index is equal to the size of
the string.

8.AccessControlException

public class AccessControlException


extends SecurityException

This exception is thrown by the AccessController to indicate that a requested


access (to a critical system resource such as the file system or the network) is
denied.

The reason to deny access can vary. For example, the requested permission
might be of an incorrect type, contain an invalid value, or request access that
is not allowed according to the security policy. Such information should be
given whenever possible at the time the exception is thrown.

9.GeneralSecurityException
public class GeneralSecurityException
extends Exception
The GeneralSecurityException class is a generic security exception class that
provides type safety for all the security-related exception classes that extend
from it.
10.KeyManagementException

public class KeyManagementException


extends KeyException
This is the general key management exception for all operations dealing with
key management. Examples of subclasses of KeyManagementException that
developers might create for giving more detailed information could include:

• KeyIDConflictException
• KeyAuthorizationFailureException
• ExpiredKeyException

11.PrivilegedActionException
public class PrivilegedActionException
extends Exception
This exception is thrown by doPrivileged(PrivilegedExceptionAction) and
doPrivileged(PrivilegedExceptionAction, AccessControlContext context) to
indicate that the action being performed threw a checked exception. The
exception thrown by the action can be obtained by calling the getException
method. In effect, an PrivilegedActionException is a "wrapper" for an
exception thrown by a privileged action.

As of release 1.4, this exception has been retrofitted to conform to the general
purpose exception-chaining mechanism. The "exception thrown by the
privileged computation" that is provided at construction time and accessed via
the getException() method is now known as the cause, and may be accessed
via the Throwable.getCause() method, as well as the aforementioned "legacy
method."

12. TooManyListenersException

public class TooManyListenersException


extends Exception

The TooManyListenersException Exception is used as part of the Java Event


model to annotate and implement a unicast special case of a multicast Event
Source.

The presence of a "throws TooManyListenersException" clause on any given


concrete implementation of the normally multicast "void addXyzEventListener"
event listener registration pattern is used to annotate that interface as
implementing a unicast Listener special case, that is, that one and only one
Listener may be registered on the particular event listener source
concurrently.
13. HeadlessException

public class HeadlessException

extends UnsupportedOperationException

Thrown when code that is dependent on a keyboard, display, or mouse is


called in an environment that does not support a keyboard, display, or mouse.

14. IllegalComponentStateException

public class IllegalComponentStateException


extends IllegalStateException
Signals that an AWT component is not in an appropriate state for the
requested operation.

15. ParseException
public class ParseException
extends Exception
Signals that an error has been reached unexpectedly while parsing.

16. AccessException

public class AccessException


extends RemoteException
An AccessException is thrown by certain methods of the java.rmi.Naming
class (specifically bind, rebind, and unbind) and methods of the
java.rmi.activation.ActivationSystem interface to indicate that the caller does
not have permission to perform the action requested by the method call. If the
method was invoked from a non-local host, then an AccessException is
thrown.

17. MarshalException

public class MarshalException


extends RemoteException
A MarshalException is thrown if a java.io.IOException occurs while
marshalling the remote call header, arguments or return value for a remote
method call. A MarshalException is also thrown if the receiver does not
support the protocol version of the sender.

If a MarshalException occurs during a remote method call, the call may or


may not have reached the server. If the call did reach the server, parameters
may have been deserialized. A call may not be retransmitted after a
MarshalException and reliably preserve "at most once" call semantics.
18. RemoteException
public class RemoteException
extends IOException
A RemoteException is the common superclass for a number of
communication-related exceptions that may occur during the execution of a
remote method call. Each method of a remote interface, an interface that
extends java.rmi.Remote, must list RemoteException in its throws clause.

As of release 1.4, this exception has been retrofitted to conform to the general
purpose exception-chaining mechanism. The "wrapped remote exception"
that may be provided at construction time and accessed via the public detail
field is now known as the cause, and may be accessed via the
Throwable.getCause() method, as well as the aforementioned "legacy field."

19. ServerError

public class ServerError

extends RemoteException

A ServerError is thrown as a result of a remote method invocation when an


Error is thrown while processing the invocation on the server, either while
unmarshalling the arguments, executing the remote method itself, or
marshalling the return value. A ServerError instance contains the original
Error that occurred as its cause.

20. StubNotFoundException

public class StubNotFoundException

extends RemoteException

A StubNotFoundException is thrown if a valid stub class could not be found


for a remote object when it is exported. A StubNotFoundException may also
be thrown when an activatable object is registered via the
java.rmi.activation.Activatable.register method.

21. UnexpectedException

public class UnexpectedException

extends RemoteException

An UnexpectedException is thrown if the client of a remote method call


receives, as a result of the call, a checked exception that is not among the
checked exception types declared in the throws clause of the method in the
remote interface.
22. UnknownHostException

public class UnknownHostException

extends RemoteException

An UnknownHostException is thrown if a java.net.UnknownHostException


occurs while creating a connection to the remote host for a remote method
call.

23. UnmarshalException

public class UnmarshalException

extends RemoteException

An UnmarshalException can be thrown while unmarshalling the parameters or


results of a remote method call if any of the following conditions occur:

• if an exception occurs while unmarshalling the call header

• if the protocol for the return value is invalid

• if a java.io.IOException occurs unmarshalling parameters (on the


server side) or the return value (on the client side).

• if a java.lang.ClassNotFoundException occurs during unmarshalling


parameters or return values

• if no skeleton can be loaded on the server-side; note that skeletons are


required in the 1.1 stub protocol, but not in the 1.2 stub protocol.

• if the method hash is invalid (i.e., missing method).

• if there is a failure to create a remote reference object for a remote


object's stub when it is unmarshalled.

24. IntrospectionException

public class IntrospectionException

extends Exception
Thrown when an exception happens during Introspection.

Typical causes include not being able to map a string class name to a Class
object, not being able to resolve a string method name, or specifying a
method name that has the wrong type signature for its intended use.
25. EOFException

public class EOFException

extends IOException

Signals that an end of file or end of stream has been reached unexpectedly
during input.

This exception is mainly used by data input streams to signal end of stream.
Note that many other input operations return a special value on end of stream
rather than throwing an exception.

26. InvalidClassException

public class InvalidClassException

extends ObjectStreamException

Thrown when the Serialization runtime detects one of the following problems
with a Class.

• The serial version of the class does not match that of the class
descriptor read from the stream

• The class contains unknown datatypes

• The class does not have an accessible no-arg constructor

27. InvalidObjectException

public class InvalidObjectException

extends ObjectStreamException

Indicates that one or more deserialized objects failed validation tests. The
argument should provide the reason for the failure.

28. IOException

public class IOException

extends Exception

Signals that an I/O exception of some sort has occurred. This class is the
general class of exceptions produced by failed or interrupted I/O operations.
29. NotSerializableException

public class NotSerializableException

extends ObjectStreamException

Thrown when an instance is required to have a Serializable interface. The


serialization runtime or the class of the instance can throw this exception. The
argument should be the name of the class.

30. StreamCorruptedException

public class StreamCorruptedException

extends ObjectStreamException

Thrown when control information that was read from an object stream violates
internal consistency checks.

31. UTFDataFormatException

public class UTFDataFormatException

extends IOException

Signals that a malformed UTF-8 string has been read in a data input stream
or by any class that implements the data input interface. See the writeUTF
method for the format in which UTF-8 strings are read and written.

32. ProfileDataException

public class ProfileDataException

extends RuntimeException

This exception is thrown when an error occurs in accessing or processing an


ICC_Profile object.

33. BindException

public class BindException

extends SocketException

Signals that an error occurred while attempting to bind a socket to a local


address and port. Typically, the port is in use, or the requested local address
could not be assigned.
34. ConnectException

public class ConnectException

extends SocketException

Signals that an error occurred while attempting to connect a socket to a


remote address and port. Typically, the connection was refused remotely
(e.g., no process is listening on the remote address/port).

35. NoRouteToHostException

public class NoRouteToHostException

extends SocketException

Signals that an error occurred while attempting to connect a socket to a


remote address and port. Typically, the remote host cannot be reached
because of an intervening firewall, or if an intermediate router is down.

36. UnknownServiceException

public class UnknownServiceException

extends IOException

Thrown to indicate that an unknown service exception has occurred. Either


the MIME type returned by a URL connection does not make sense, or the
application is attempting to write to a read-only URL connection.

37. URISyntaxException

public class URISyntaxException

extends Exception

Checked exception thrown to indicate that a string could not be parsed as a


URI reference.

38. SocketTimeoutException

public class SocketTimeoutException

extends InterruptedIOException

Signals that a timeout has occurred on a socket read or accept.


39. SocketException

public class SocketException

extends IOException

Thrown to indicate that there is an error in the underlying protocol, such as a


TCP error.

40. ProtocolException

public class ProtocolException

extends IOException

Thrown to indicate that there is an error in the underlying protocol, such as a


TCP error.

You might also like