views:

104

answers:

1

How do you go about catching this exception in a servlet that takes longer than 30 seconds?

Thanks!

+2  A: 

You can use a normal try-catch around your code and catch the DeadlineExceededException:

import com.google.apphosting.api.DeadlineExceededException

try {
  // your code
} catch (DeadlineExceededException e) {
  // do something here to handle the exception in a user-friendly way
}

Do remember that your time available after catching the DeadlineExceededException is limited. So you can't execute a lot of code inside the catch, because it will generate a HardDeadlineExceededError after a short period (generally < 1 sec).

So use it wisely and just return a message to user or do a quick cleanup to rollback anything if necessary.

tomlog
Awesome, thanks. I was doing that exactly, but it would show the Error 500 message, not because of exceeding the deadline, but because of too much memory being used by my test application.Thanks!
edarroyo