Maze / Library /PackageCache /com.unity.visualscripting@1.8.0 /Runtime /VisualScripting.Flow /Framework /Control /Throw.cs
| using System; | |
| namespace Unity.VisualScripting | |
| { | |
| /// <summary> | |
| /// Throws an exception. | |
| /// </summary> | |
| [] | |
| [] | |
| public sealed class Throw : Unit | |
| { | |
| /// <summary> | |
| /// Whether a custom exception object should be specified manually. | |
| /// </summary> | |
| [] | |
| [] | |
| [] | |
| public bool custom { get; set; } | |
| /// <summary> | |
| /// The entry point to throw the exception. | |
| /// </summary> | |
| [] | |
| [] | |
| public ControlInput enter { get; private set; } | |
| /// <summary> | |
| /// The message of the exception. | |
| /// </summary> | |
| [] | |
| public ValueInput message { get; private set; } | |
| /// <summary> | |
| /// The exception to throw. | |
| /// </summary> | |
| [] | |
| public ValueInput exception { get; private set; } | |
| protected override void Definition() | |
| { | |
| if (custom) | |
| { | |
| enter = ControlInput(nameof(enter), ThrowCustom); | |
| exception = ValueInput<Exception>(nameof(exception)); | |
| Requirement(exception, enter); | |
| } | |
| else | |
| { | |
| enter = ControlInput(nameof(enter), ThrowMessage); | |
| message = ValueInput(nameof(message), string.Empty); | |
| Requirement(message, enter); | |
| } | |
| } | |
| private ControlOutput ThrowCustom(Flow flow) | |
| { | |
| throw flow.GetValue<Exception>(exception); | |
| } | |
| private ControlOutput ThrowMessage(Flow flow) | |
| { | |
| throw new Exception(flow.GetValue<string>(message)); | |
| } | |
| } | |
| } | |