Pull down EvaluationFailureException.

This commit is contained in:
2023-01-13 22:18:13 +08:00
parent 5b14466059
commit 4f93995bbd
3 changed files with 21 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Cryville.Common.Pdt { namespace Cryville.Common.Pdt {
/// <summary> /// <summary>
@@ -167,10 +168,10 @@ namespace Cryville.Common.Pdt {
internal void Operate(PdtOperatorSignature sig) { internal void Operate(PdtOperatorSignature sig) {
PdtOperator op; PdtOperator op;
try { op = GetOperator(sig); } try { op = GetOperator(sig); }
catch (Exception) { catch (Exception ex) {
for (int i = 0; i < sig.ParamCount; i++) for (int i = 0; i < sig.ParamCount; i++)
DiscardStack(); DiscardStack();
throw; throw new EvaluationFailureException(string.Format("Failed to get operator {0}", sig), ex);
} }
Operate(op, sig.ParamCount); Operate(op, sig.ParamCount);
} }
@@ -222,4 +223,18 @@ namespace Cryville.Common.Pdt {
_goffset -= _stack[--_framecount].Length; _goffset -= _stack[--_framecount].Length;
} }
} }
/// <summary>
/// The exception that is thrown when the evalution of a <see cref="PdtExpression" /> fails.
/// </summary>
public class EvaluationFailureException : Exception {
/// <inheritdoc />
public EvaluationFailureException() : base("Evaluation failed") { }
/// <inheritdoc />
public EvaluationFailureException(string message) : base(message) { }
/// <inheritdoc />
public EvaluationFailureException(string message, Exception innerException) : base(message, innerException) { }
/// <inheritdoc />
protected EvaluationFailureException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
} }

View File

@@ -48,9 +48,9 @@ namespace Cryville.Common.Pdt {
_rfreq = false; _rfreq = false;
try { Execute(); } catch (Exception ex) { try { Execute(); } catch (Exception ex) {
if (_rfreq) _etor.DiscardStack(); if (_rfreq) _etor.DiscardStack();
throw new InvalidOperationException("Evaluation failed", ex); throw new EvaluationFailureException("Evaluation failed", ex);
} }
if (!_rfreq && !noset) throw new InvalidOperationException("Return frame not set"); if (!_rfreq && !noset) throw new EvaluationFailureException("Return frame not set");
} }
/// <summary> /// <summary>
/// Executes the operator. /// Executes the operator.

View File

@@ -142,7 +142,8 @@ namespace Cryville.Crtr {
return _flag ? a : null; return _flag ? a : null;
} }
catch (Exception) { catch (Exception) {
throw new SelectorNotStaticException(); if (dyn) throw;
else throw new SelectorNotStaticException();
} }
finally { finally {
ChartPlayer.etor.ContextTransform = null; ChartPlayer.etor.ContextTransform = null;