Stop runtime and send error

Hello i have a part of code and want the engine to stop runtime and send an error line instead of crashing when affected object does not have a UAROTARGET component.
The code is: c

UActorComponent* tempTargetComp;
     for (int object = 0; object < affectedObjects.Num(); ++object) {
         tempTargetComp = affectedObjects[object]->GetComponentByClass(UAROTarget::StaticClass());
         if (tempTargetComp != nullptr) {
             targetAROComponent[object] = dynamic_cast<UAROTarget>(tempTargetComp);
         }
     }

Hi. This code will show a message and close a game then.

const FText Message = ...Your message...

FMessageDialog::Open(EAppMsgType::Ok, Message); // Show message
FPlatformMisc::RequestExit(false); // Exit application

The problem i have is the crash just when runtime starts that Beginplay() is running on all scripts

Sorry. If it crashes try to use Cast<…>() instead of dynamic_cast

No luck either, code now looks like this:

tempTargetComp = affectedObjects[object]->GetComponentByClass(UAROTarget::StaticClass());
		if (tempTargetComp != nullptr) {
			targetAROComponent[object] = Cast<UAROTarget>(tempTargetComp);
			if (targetAROComponent[object] == nullptr) {
				FPlatformMisc::RequestExit(false);
			}
		} else {
			FPlatformMisc::RequestExit(false);
		}

But the problem is doesnt matter if i exit with or without finishing the loop it crashes because it tries to do at leats once the update (and because of code and arrays and stuff in cant do the update correctly if there is a nullptr in the array)

Maybe it crashes on a first line, where you using affectedObjects[object] without any checks.