Selathco 0.91 generated HTML
Predchozi Table of contents ) Dalsi

4. System of Exceptions

In Java, exceptions are an undetachable part of the language. Their usage is mandatory which prevents programmers from ignoring them. Because it is a very useful mechanism to signal an error or an unpredicted situation to an upper level of execution, J-Sim introduces some new exception classes, too. They are as follows:

  • JSimException

  • JSimInvalidParametersException

  • JSimSimulationAlreadyTerminatedException

  • JSimTooManyProcessesException

  • JSimKernelPanicException

  • JSimProcessDeath

4.1. Standard Exceptions

4.1.1. JSimException

The JSimException class is an extremely important exception, although it does not have any instances. It is a basic class that all other exceptions (except for JSimKernelPanicException and JSimProcessDeath) are derived from. All its subclasses inherit a variable called specific where the exact reason why the exception was thrown out is usually stored. This class, as well as all its subclasses, provides a constructor whose one parameter is reserved for that purpose.

The printComment() method, which should be rewritten in every subclass, is supposed to inform the user in a comprehensible way about the general reasons why this type of exception is usually thrown out. It prints the message into a PrintStream which must be specified. The method's header:


public void printComment(PrintStream ps)

The getSpecific() method returns a string containing information about specific circumstances of this exception. This information should always be given to one of the two constructors available in JSimException. The method's header:

public String getSpecificInfo()

The two constructors allow either to specify a short description of the exception or to use a default one, but the specific reason must be always given to them:

public JSimException(String description, String param)
public JSimException(String param)

This class of exception and all its subclasses must be always caught or explicitly stated in the list of exceptions thrown out by a method.

4.1.2. JSimInvalidParametersException

The JSimInvalidParametersException class is inherited from JSimException and therefore keeps all its possibilities. It is thrown out whenever a method gets arguments that cannot be used because their values are invalid (e.g. a negative number) or are not given at all (e.g. a null reference).

In JSimInvalidParametersException, only one constructor is present, using an implicite description:


public JSimInvalidParametersException(String pars)

The printComment() method is overwritten in an appropriate way.

4.1.3. JSimSimulationAlreadyTerminatedException

An instance of this exception is thrown out from JSimProcess' constructor when the simulation that the new process is to be inserted in is already terminated. A simulation is terminated if there are no more processes or no more scheduled events.

In JSimSimulationAlreadyTerminatedException, only one constructor is present, using an implicite description:


public JSimSimulationAlreadyTerminatedException(String pars)

The printComment() method is overwritten in an appropriate way.

4.1.4. JSimTooManyProcessesException

An instance of this exception is thrown out from JSimProcess' constructor when the simulation cannot assign a new number to the newly created process because the internal counter of created processes has reached its upper limit. The upper limit is equal to Long.MAX_VALUE which is 9 223 372 036 854 775 807. Once a process is created, its number gets occupied forever and even if the process terminates, the number is not available anymore. Therefore, this exception can be thrown out even if very few processes (e.g. 3) are currently running in the simulation, but the simulation has already contained nearly the limit of processes which have died.

In JSimTooManyProcessesException, only one constructor is present, using an implicite description:


public JSimTooManyProcessesException(String pars)

The printComment() method is overwritten in an appropriate way.

4.2. Nonstandard Exceptions

4.2.1. JSimKernelPanicException

Unlike exceptions discussed in chapter 4.1., the JSimKernelPanicException is a subclass of RuntimeException and therefore need not be caught or explicitly stated in the list of exceptions thrown out from a method. It is used when the J-Sim kernel (typically JSimSimulation or JSimProcess) finds an inconsistency in data which cannot be repaired. Throwing out this exception usually leads to deadlock because the currently running thread is the only active one in the system and the exception is propagated until the JVM which will finally kill it. However, the purpose of this exception is not to stabilize the system, the purpose is to let the developer know that there is a weak point in the system. The constructor has no parameters:


public JSimKernelPanicException()

4.2.2. JSimProcessDeath

The JSimProcessDeath exception is an internal J-Sim exception which should not be used by the user - it should neither be thrown nor caught. It is thrown out by a process itself when it gets a killing signal from its simulation. The exception can be thrown out from these methods: getReady(), hold() and passivate(). Because hold() and passivate() are invoked from life() and this method does not catch the exception, it is propagated until run() where it is finally caught. Detailed information about JSimProcessDeath can be found in chapter 2.4..

JSimProcessDeath is a subclass of RuntimeException and has one constructor without parameters:


public JSimProcessDeath()

JSimProcessDeath is an equivalent of Java's ThreadDeath used when a thread is killed using its stop() (1) method.


  • (1) This method has been deprecated.

Predchozi
Converted by Selathco 0.91 on 01.09.2001 18:44
Dalsi