public JsNode VisitThrowStatement(ThrowStatement node) { JsExpression node2; IType exceptionType; if (node.Expression == null || node.Expression.IsNull) //happens when performing "throw;" { var cc = node.GetParent <CatchClause>(); if (cc != null) { node2 = Js.Member(cc.VariableName); var type = cc.Type; if (type == null || type.IsNull) { exceptionType = Project.Compilation.FindType(KnownTypeCode.Exception); } else { exceptionType = cc.Type.Resolve().Type; } } else { throw new Exception("Rethrow not supported, catch clause not found"); } } else { node2 = VisitExpression(node.Expression); var res = node.Expression.Resolve(); exceptionType = res.Type; if (res is ConversionResolveResult) { exceptionType = ((ConversionResolveResult)res).Input.Type; } } if (!Sk.IsNativeError(exceptionType.GetDefinitionOrArrayType())) { node2 = Js.Member("$CreateException").Invoke(node2, Js.New(Js.Member("Error"))); } return(new JsThrowStatement { Expression = node2 }); }
public JNode VisitThrowStatement(ThrowStatement node) { JExpression node2; IType exceptionType; if (node.Expression == null || node.Expression.IsNull) //happens when performing "throw;" { var cc = node.GetParent <CatchClause>(); if (cc != null) { node2 = J.Member(cc.VariableName); var type = cc.Type; if (type == null || type.IsNull) { exceptionType = Project.Compilation.FindType(KnownTypeCode.Exception); } else { exceptionType = cc.Type.Resolve().Type; } } else { throw new Exception("Rethrow not supported, catch clause not found"); } } else { node2 = VisitExpression(node.Expression); exceptionType = node.Expression.Resolve().Type; } //if (!Sk.IsNativeError(exceptionType.GetDefinitionOrArrayType())) //{ // throw new NotSupportedException(); // //node2 = J.Member("$CreateException").Invoke(node2, J.New(J.Member("Error"))); //} return(new JThrowStatement { Expression = node2 }); }
public override void VisitThrowStatement (ThrowStatement throwStatement) { base.VisitThrowStatement (throwStatement); if (throwStatement.Expression.IsNull) { var cc = throwStatement.GetParent<CatchClause> (); if (cc != null) { throwStatement.Expression = new IdentifierExpression (cc.VariableName); } } }