Format Error Messages

The following table describes error messages that can result from incorrect script format. A format error message starts with the following error prefix: Syntax error at line line# position character#.

Message Example Cause

Expected ':'

Example 1
function main ()
{
  var a = false;
  var b = a ? 1, 2; 
  //expect : after 1
}
Example 2
function main ()
{
  var a = {prop1:1, prop2}; 
// expect : after prop2
}
Example 3
function main ()
{
  var a = 1;
  var b;
  switch (a)
  {
  case 1  
  //expect : after 1
  b =a;
  default  
//expect : after default
  b = 0;
  }
}

A colon (:) character is required in the context but you did not provide one. To correct the error, you do the following:

  • In an expression using the conditional operator, make sure you include a colon between the second and third operands.

  • In a Switch statement, make sure you include a colon after the value in the Case statement. For example, see example 3.

Expected ';'

function main ()
{
  for (i=1; i<10 i++) 
//miss ; after i<10
  {
  ...
  }
}

A semi-colon (;) character is required in the context but you did not provide one.

A semi-colon is used to end a statement. Make sure you do the following:

  • End each statement with a semi-colon.

  • Include a semi-colon in the For Loop statement.

Expected '('

function main <> 
//expect ( after main
{
  ...
}

The open parenthesis ( ( ) and the close parenthesis ( ) ) do not pair up.

Expected ')'.

Not applicable

The open parenthesis ( ( ) and the close parenthesis ( ) ) do not pair up.

Expected ']'.

function main ()
{
  var a = new Array (10);
  a[10 = 1;
//expect ] after a[10 = 1
}

The open bracket ( [ ) and the close bracket ( ] ) do not pair up.

Expected '{'.

function main ()
var a = new Array (1); 
//expect { before var

The open brace ( { ) and the close brace ( } ) do not pair up.

Expected '}'.

Not applicable

The open brace ( { ) and the close curly brace ( } ) do not pair up.

Expected identifier.

function () 
// Expect an identifier after
// function */
{
  ...
}
function main ()
{
  var; 
// Expect an identifier after var
}

A name is required in the context but you did not provide one. The name can include one of the following items:

  • Variable

  • Property

  • Array

  • Function name

Invalid token.

function main ()
{
 var a = "\u000G";
// '\u000G' is an invalid
// unicode character combination 
}
function main ()
{
 var a = "\u0G"; 
// '\u0G' is an invalid hex
// character combination 
}

An invalid Unicode character combination or an invalid hex character combination exists.

Expected while.

function main ()
{

  {
  ...
  }
// Expect while on this line
}

The Do While statement is not complete. A while method is required to complete the statement but you did not provide one.

Throw must be followed by an expression on the same line.

try
{
var a = 
TheApplication().GetService(“Incorrect
name”);
}
catch( e )
{
  throw ;
// The Throw statement expects an 
// expression which is not supplied 

// It must be: throw e;

}

The Throw statement must be followed by a name that identifies an exception on the same line, but you did not provide an expression of this type.

Invalid continue statement.

function main ()
{
  continue; 
// Continue is not in a loop
}

The Continue statement is not in the body of one of the following items:

  • Do while

  • While

  • For

  • For in

Invalid Break statement.

function BreakError()
{
  break;
// Break is not in a valid loop
}

The Break statement is not in the body of one of the following items:

  • Do while

  • While

  • For

  • For in

Invalid return statement. Return statement cannot be used outside the function body.

function fn ()
{
  ...
}
return; 
// Return is outside the function body.

A Return statement exists outside the body of a function but it must exist in the body of a function.

Invalid left-hand side value.

function main ()
{
 new Object () = 1; 
// new Object () is not a valid
// left value
}

The preceding value in an assignment operation must be compatible with the value assigned.

In the example, the New Object statement is an invalid left-hand value for the equal (=) assignment operator. The valid preceding value must contain a variable.

Invalid regular expression.

var oRegExp:RegExp;
oRegExp = /[a-c*/;
// The regular expression is 
// missing the closing ]. It 
// must be [a-c]*.

The regular expression is invalid. For example, the closing bracket ( ] ) is missing.