When Things Go Wrong

ComputeException

The Task classes you define may not be perfect, at first. When you are testing a Task class, its execute method may throw an Exception. When this occurs the HSP compute method: 
  • throws a ComputeException
  • logs out the application
The oops! example illustrates such a case: It is a Jicos program in which a task, BadTask.java, causes an Exception to be thrown. Here is the code: In the Application class, the compute method invocation is within a try-catch. If your application is merely the invocation of a main method, then, when a ComputeException is thrown, you do not have to place it within a try-catch, provided that you don't mind the main method terminating. In this case, the system prints out the contents of the ComputeException for you. In subsequent examples, we omit the try-catch block.

The output provides:

  • the type of Exception
  • the name of the class in which it was thrown and the line number within the class
  • a stacktrace.
In the example, the output should look like this (line 8 of BadTask.java is indeed where the divide by 0 occurs):

java.lang.ArithmeticException: / by zero
jicos.services.ComputeException: java.lang.ArithmeticException: / by zero
 at jicos.examples.computeexception.BadTask.execute(BadTask.java:8)
 at jicos.services.Host.executeTask(Host.java:206)
 at jicos.services.commands.ExecuteTask.execute(ExecuteTask.java:19)
 at jicos.foundation.Department$Processor.run(Department.java:85)
 at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
 at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
 at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
 at jicos.services.Hsp_Stub.compute(Unknown Source)
 at jicos.examples.computeexception.Application.main(Application.java:31)