diff --git a/src/pocketmine/scheduler/TaskHandler.php b/src/pocketmine/scheduler/TaskHandler.php index 8e04778b7..bb1f5212d 100644 --- a/src/pocketmine/scheduler/TaskHandler.php +++ b/src/pocketmine/scheduler/TaskHandler.php @@ -25,6 +25,7 @@ namespace pocketmine\scheduler; use pocketmine\event\Timings; use pocketmine\event\TimingsHandler; +use pocketmine\utils\MainLogger; class TaskHandler{ @@ -136,10 +137,15 @@ class TaskHandler{ * Changes to this function won't be recorded on the version. */ public function cancel(){ - if(!$this->isCancelled()){ - $this->task->onCancel(); + try{ + if(!$this->isCancelled()){ + $this->task->onCancel(); + } + }catch(\Throwable $e){ + MainLogger::getLogger()->logException($e); + }finally{ + $this->remove(); } - $this->remove(); } public function remove(){