Skip to content

Commit e721e13

Browse files
committed
Special evaluator exception type (EvaluatorExceptionThrownException) that wraps target process exception that occurred during runtime call. This allows to inspect exception objects in watch window if eval thrown an exception.
1 parent fcc4bc5 commit e721e13

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Mono.Debugging/Mono.Debugging.Client/ObjectValue.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using System.Linq;
3333

3434
using Mono.Debugging.Backend;
35+
using Mono.Debugging.Evaluation;
3536

3637
namespace Mono.Debugging.Client
3738
{
@@ -151,8 +152,18 @@ public static ObjectValue CreateError (IObjectValueSource source, ObjectPath pat
151152
val.value = value;
152153
return val;
153154
}
154-
155-
public static ObjectValue CreateImplicitNotSupported (IObjectValueSource source, ObjectPath path, string typeName, ObjectValueFlags flags)
155+
156+
public static ObjectValue CreateEvaluationException (EvaluationContext ctx, IObjectValueSource source, ObjectPath path, EvaluatorExceptionThrownException exception,
157+
ObjectValueFlags flags = ObjectValueFlags.None)
158+
{
159+
var error = CreateError (source, path, exception.ExceptionTypeName, "Exception was thrown", flags);
160+
var exceptionReference = LiteralValueReference.CreateTargetObjectLiteral (ctx, "Exception", exception.Exception);
161+
var exceptionValue = exceptionReference.CreateObjectValue (ctx.Options);
162+
error.children = new List<ObjectValue> {exceptionValue};
163+
return error;
164+
}
165+
166+
public static ObjectValue CreateImplicitNotSupported (IObjectValueSource source, ObjectPath path, string typeName, ObjectValueFlags flags)
156167
{
157168
var val = Create (source, path, typeName);
158169
val.flags = flags | ObjectValueFlags.ImplicitNotSupported;

Mono.Debugging/Mono.Debugging.Evaluation/ExpressionEvaluator.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,28 @@ public virtual ValueReference GetCurrentException (EvaluationContext ctx)
199199
[Serializable]
200200
public class EvaluatorException: Exception
201201
{
202+
202203
protected EvaluatorException (SerializationInfo info, StreamingContext context)
203204
: base (info, context)
204205
{
205206
}
206207

207-
public EvaluatorException (string msg, params object[] args): base (string.Format (msg, args))
208+
public EvaluatorException (string msg, params object[] args): base (string.Format(msg, args))
209+
{
210+
}
211+
}
212+
213+
[Serializable]
214+
public class EvaluatorExceptionThrownException : EvaluatorException
215+
{
216+
public EvaluatorExceptionThrownException (object exception, string exceptionTypeName) : base ("Exception is thrown")
208217
{
218+
Exception = exception;
219+
ExceptionTypeName = exceptionTypeName;
209220
}
221+
222+
public object Exception { get; private set; }
223+
public string ExceptionTypeName { get; private set; }
210224
}
211225

212226
[Serializable]

Mono.Debugging/Mono.Debugging.Evaluation/ObjectValueAdaptor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,8 @@ public ObjectValue GetExpressionValue (EvaluationContext ctx, string exp)
13551355
return ObjectValue.CreateImplicitNotSupported (ctx.ExpressionValueSource, new ObjectPath (exp), "", ObjectValueFlags.None);
13561356
} catch (NotSupportedExpressionException ex) {
13571357
return ObjectValue.CreateNotSupported (ctx.ExpressionValueSource, new ObjectPath (exp), "", ex.Message, ObjectValueFlags.None);
1358+
} catch (EvaluatorExceptionThrownException ex) {
1359+
return ObjectValue.CreateEvaluationException (ctx, ctx.ExpressionValueSource, new ObjectPath (exp), ex);
13581360
} catch (EvaluatorException ex) {
13591361
return ObjectValue.CreateError (ctx.ExpressionValueSource, new ObjectPath (exp), "", ex.Message, ObjectValueFlags.None);
13601362
} catch (Exception ex) {

0 commit comments

Comments
 (0)