@HareeshMR mentions a good way. Check the time before the activity, and compare it to MaxTime (e.g. Now.Addminutes(15) would wait 15 minutes). If MaxTime is reached, then it’s an application error and the process can be restarted.
However, sometimes this does not work. A good example is with excel and macros. If your VBA code has any pop-up boxes or errors occur while it is running, the robot will continue running forever because it doesn’t detect an error and is stuck on that one processing step. I’ve noticed this in other proprietary applications that have pop-ups as well. As far as i know, the only way to fix that is to log in to the robot machine and click the pop-up yourself or to kill the process