parseTry method

Statement parseTry()

Implementation

Statement parseTry() {
  int start = token?.startOffset??0;
  int line = token?.line??0;
  assert(token?.text == 'try');
  consume(Token.NAME);
  BlockStatement body = parseBlock();
  CatchClause? handler;
  BlockStatement? finalizer;
  if (peekName('catch')) {
    Token? catchTok = next();
    consume(Token.LPAREN);
    Name name = parseName();
    consume(Token.RPAREN);
    BlockStatement catchBody = parseBlock();
    handler = new CatchClause(name, catchBody)
      ..start = catchTok?.startOffset??0
      ..end = endOffset
      ..line = catchTok?.line??0
      ..endLine = body.endLine;
  }
  if (tryName('finally')) {
    finalizer = parseBlock();
  }
  return new TryStatement(body, handler, finalizer)
    ..start = start
    ..end = endOffset
    ..line = line;
}