Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ExceptCommand for all exceptions with test

  • Loading branch information...
commit e9be347d0fddfdedcad488a6f3bf79e3526331b1 1 parent 972fca4
@ajlopez authored
View
12 Src/PythonSharp.Tests/Commands/ExceptCommandTests.cs
@@ -35,6 +35,18 @@ public void CatchBaseException()
}
[TestMethod]
+ public void CatchAllExceptions()
+ {
+ ExceptCommand command = new ExceptCommand(null, null);
+
+ Assert.IsNull(command.Expression);
+ Assert.IsNull(command.Command);
+ Assert.IsTrue(command.CatchException(null, new ValueError(null)));
+ Assert.IsTrue(command.CatchException(null, new SyntaxError(null)));
+ Assert.IsTrue(command.CatchException(null, new Exception()));
+ }
+
+ [TestMethod]
public void RaiseIfExpressionIsNotAnException()
{
ExceptCommand command = new ExceptCommand(new ConstantExpression(1), null);
View
3  Src/PythonSharp/Commands/ExceptCommand.cs
@@ -25,6 +25,9 @@ public ExceptCommand(IExpression expression, ICommand command)
public bool CatchException(IContext context, Exception exception)
{
+ if (this.expression == null)
+ return true;
+
var value = this.expression.Evaluate(context);
if (!(value is Type) || !((Type)value == typeof(Exception) || ((Type)value).IsSubclassOf(typeof(Exception))))
Please sign in to comment.
Something went wrong with that request. Please try again.