Add throws clause to run() method of TimeTask object
843833Feb 2 2006 — edited Feb 14 2006I am creating a struts application.
I have an action class that creates an object of Timer class and calls its schedule() method with a parameter of the TimerTask object. This method call executes the code written in the run() method of the TimerTask object.
My problem is that I want to return a user defined exception from this run method to the calling class i.e. the action class. But the run() method of the TimeTask object does not support any "throws" clause.
Any suggestions?
This is the code:
//Action Class:::::::::::::::::::::::::
public class Schedule extends LookupDispatchAction
{
public ActionForward startSchedule (ActionMapping am, ActionForm af,
HttpServletRequest req, HttpServletResponse res) throws Exception
{
Timer objTimer = new Timer();
OspTimerTask objOspTimerTask = new OspTimerTask();
Calendar cal = Calendar.getInstance();
objTimer.schedule(objOspTimerTask,cal.getTime(),interMilliSec);
// some code..
return...
}
}
//TimerTask implementation:::::::::::::::::::::::::::::::::::::::::::::
public class OspTimerTask extends TimerTask
{
public void run() <I want "throws" clause here>
{
try
{
//some code...
}
catch(SQLExecption e)
{
throw new UserDefinedException("My Message");
}
}
}