Skip to content

Game.Debug.TestScenarioHelperUnhandledException

Assembly: Assembly-CSharp (in-game)

Namespace: Game.Debug

Type: class

Base: UnityEngine.MonoBehaviour

Summary: A small test helper MonoBehaviour used to intentionally throw an unhandled exception from a coroutine after a short delay. Useful in test scenarios for validating the game's exception logging, crash reporting, or any systems that monitor unhandled exceptions during runtime. This should not be included in production builds.


Fields

  • (none) This class has no explicit fields; it only uses local variables inside its coroutine.

Properties

  • (none) No public or private properties are declared on this type.

Constructors

  • public TestScenarioHelperUnhandledException() The default parameterless constructor is provided implicitly by Unity. Instances are normally created by attaching the component to a GameObject in a scene or by using AddComponent().

Methods

  • private void Start() Starts the coroutine CoThrowUnhandledException when the component is enabled. Called by Unity when the GameObject becomes active.

  • private IEnumerator CoThrowUnhandledException() Waits for 5 seconds (yield return new WaitForSeconds(5f)) and then throws a System.Exception with the message "TestScenarioHelperUnhandledException". Purpose is to produce an unhandled exception from a coroutine to test exception handling/logging pipelines. Note: Unity will typically log the exception and stack trace to the console; behavior for "unhandled" exceptions may depend on the runtime/modding environment and any global exception handlers.

Usage Example

// Create a GameObject and attach the helper to trigger an exception after 5 seconds.
var go = new GameObject("TestUnhandledExceptionHelper");
go.AddComponent<Game.Debug.TestScenarioHelperUnhandledException>();

// Alternatively, add the component in the Unity editor to an existing GameObject.

Additional notes: - Intended for testing only. Remove or disable this component when not actively testing exception handling. - If you need to test specific exception-reporting integrations (crash reporters, telemetry, mod frameworks), ensure they are initialized before this component runs so the thrown exception is captured as desired.