Q:

Java generate random solution

I am doing scheduling system and it will produce a random timetable, due to random method it will cause some of the exam can't add to the timetable and it will result stack over flow error.....
but sometime it will able to produce a complete timetable.
So I want to ask here how can i do like this:
if result == stack over flow error {
    redo the function
}

A:

It's bad idea to have stackoverflow error in your program and change the flow of execution using catch.
But if you want to do so you can surround your code in try catch block like this.
try{
//your code that is likely to produce stackoverflow error
}
catch(StackOverflowError se)
{
//do whatever you want after stackover flow.
}

