RascalTutor
Synopsis

All exceptions and errors a Rascal program can generate during execution (run time).

Description

Rascal can generate various kinds of exceptions and errors during execution (run time):

  • Runtime Exceptions are discovered during execution of the Rascal program and can be caught by the Rascal program. When a runtime exception is not caught in the program, execution is aborted.

  • Other Runtime Errors are discovered during execution of the Rascal program and cannot be caught by the Rascal program. They always lead to abortion of execution. These are the errors which can be prevented by fixing statically detected errors by the type checker.

Pitfalls
  • The structure and naming of exceptions and error messages is being revised so actual exceptions may differ from what is presented here.

  • Since the type checker is not available yet, the interpreter throws more run-time exceptions than necessary.

1. Runtime Exceptions

Synopsis

All runtime exceptions that can occur during execution of a Rascal program.

Description

The following exceptions can be trown as the result of a run-time error:

1.1. Ambiguity

Synopsis

Ambiguity found in parsed text.

Description

Rascal supports general context-free grammars and also provides various mechanisms to disambiguate them.

This exception is thrown when, given a grammar and a sentence, an ambiguity is found while parsing the sentence according to that grammar.

Examples

First declare a very simple expression language that should recognize expressions like a, a+a, a+(a+a):

rascal>syntax A = "a";
ok
rascal>syntax E = A | "(" E ")" | E "+" E;
ok

Next, import the ParseTree module that provides a parse function that we will use:

rascal>import ParseTree;
ok

Entering a first expression goes well, except that the parser generator already predicts future ambiguity. So it prints a warning.

rascal>parse(#E, "a+a");
warning, ambiguity predicted: E  "+"  E  lacks left or right associativity
 
E: (E) `a+a`

The following example triggers the predicted ambiguity indeed:

rascal>parse(#E, "a+a+a");
|TODO:///|: Ambiguity(
  |unknown:///|(0,5,<1,0>,<1,5>),
  "E",
  "a+a+a")
 
ok

The conclusion is that there are two parses here: a+(a+a) and (a+a)+a, because we did forget to define the associativity of the + operator.

Let’s fix this:

rascal>syntax A = "a";
ok
rascal>syntax E = A | "(" E ")" | left E "+" E;
ok
rascal>import ParseTree;
ok
rascal>parse(#E, "a+a+a");
|TODO:///|: Ambiguity(
  |unknown:///|(0,5,<1,0>,<1,5>),
  "E",
  "a+a+a")
 
ok

However, one can also deal with ambiguity differently. For example we could have the parser build a tree for all ambiguous interpretations and inspect the resulting data-structure:

rascal>syntax A = "a";
ok
rascal>syntax E = A | "(" E ")" | left E "+" E | left E "*" E;
ok
rascal>import ParseTree;
ok
rascal>t = parse(#E, "a+a*a", allowAmbiguity=true);
warning, ambiguity predicted: E  "*"  E  lacks left or right associativity
warning, ambiguity predicted: E  "*"  E  and E  "+"  E  lack left or right associativity or priority (>)
warning, ambiguity predicted: E  "+"  E  and E  "*"  E  lack left or right associativity or priority (>)
warning, ambiguity predicted: E  "+"  E  lacks left or right associativity
 
E: (E) `a+a*a`

Is the forest indeed ambiguous?

rascal>/amb(_) := t
bool: true

How many alternatives?

rascal>import Set;
ok
rascal>import IO;
ok
rascal>/amb(a) := t ? size(a) : 0;
int: 2

Which rules are at the top of the alternatives?

rascal>if (/amb({a1, a2}) := t)
>>>>>>>  println("alternative 1: <a1.prod>
>>>>>>>          'alternative 2: <a2.prod>");
alternative 1: prod(sort("E"),[sort("E"),layouts("$default$"),lit("+"),layouts("$default$"),sort("E")],{})
alternative 2: prod(sort("E"),[sort("E"),layouts("$default$"),lit("*"),layouts("$default$"),sort("E")],{})
ok

Or, one could catch the ambiguity and report it like a Parse Error:

rascal>import IO;
ok
rascal>try
>>>>>>>  parse(#E, "a+a*a");
>>>>>>>catch Ambiguity(loc l, str s, _):
>>>>>>>  println("the input is ambiguous for <s> on line <l.begin.line>");
the input is ambiguous for E on line 1
ok

Here are some pointers for further disambiguation help:

1.2. Arithmetic Exception

Synopsis

An arithmetic exception occurred.

Types

data RuntimeException = ArithmeticException(str message);

Usage

import Exception; (only needed when ArithmeticException is used in catch)

Description

This error is generated when an illegal arithmetic operation occurs or when a numeric function is called with an out-of-range argument.

Remedies:

  • Check the validity of the argument before you call the function or apply the operator.

  • Catch the ArithmeticException yourself, see try catch statement.

Examples

Division by 0 gives an error:

rascal>3/0;
|prompt:///|(2,1,<1,2>,<1,3>): ArithmeticException("/ by zero")
 
ok

Giving an out-of-range argument to a mathematical function also gives an error:

rascal>import util::Math;
ok
rascal>tan(-550000000000000000000000);
|std:///util/Math.rsc|(10776,261,<571,0>,<587,28>): ArithmeticException("x should be between -(pi/2) and (pi/2)")
	at *** somewhere ***(|std:///util/Math.rsc|(10776,261,<571,0>,<587,28>))
	at tan(|prompt:///|(5,24,<1,5>,<1,29>))
 
ok

We can also catch the ArithmeticException error. First import the Rascal exceptions (which are also included in Prelude) and IO:

rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try println(3/0); catch ArithmeticException(msg): println("The message is: <msg>");
The message is: / by zero
ok

1.3. Assertion Failed

Synopsis

An assertion in the Rascal code is false.

Function

data RuntimeException = AssertionFailed(str label);

Description

An Assert statement can be used to check assumptions during the execution of a Rascal program. This error is generated if an assertion is not true.

Remedies:

  • Modify your code to make the assertion true.

  • Modify your assertion to reflect the current behaviour of your code.

  • Catch the AssertionFailed yourself, see try catch.

Examples

A false assertion gives an error:

rascal>assert 3 > 4;
|prompt:///|(0,13,<1,0>,<1,13>): AssertionFailed()
	at $shell$(|main://$shell$|)
 
ok

Define a function that only increments positive integers:

rascal>int incrPositive(int n) { assert n > 0: "n should be greater than 0"; return n + 1; }
int (int): function(|prompt:///|(0,85,<1,0>,<1,85>))

Calling it with a positive integer is fine:

rascal>incrPositive(3);
int: 4

But a negative argument gives an error:

rascal>incrPositive(-3);
|prompt:///|(40,28,<1,40>,<1,68>): AssertionFailed("n should be greater than 0")
	at incrPositive(|prompt:///|(0,85,<1,0>,<1,85>))
	at $shell$(|prompt:///|(0,17,<1,0>,<1,17>))
 
ok

We can also catch the AssertionFailed error. First import the Rascal exceptions (which are also included in Prelude) and IO:

rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try println(incrPositive(-3)); catch AssertionFailed(msg): println("incrPositive: <msg>");
incrPositive: n should be greater than 0
ok
Benefits
  • Enables the precise expression of assumptions in your code.

  • Asserts are actually executed when the compiler option enableAsserts is set to true (by default set to false).

  • In the RascalShell, enableAsserts is always true.

1.4. Empty List

Synopsis

Illegal operation on an empty list.

Types

data RuntimeException = EmptyList();

Usage

import Exception; (only needed when EmptyList is used in catch)

Description

Rascal provides many operations and functions on lists, see list values and list functions. This error is generated when a function or operation cannot handle the empty list.

Remedies:

  • Guard the function or operation with a test on the empty list (isEmpty) and take alternative action in that case.

  • Catch the EmptyList yourself, see try catch.

Examples

Import the List library and introduce L with an empty list as value:

rascal>import List;
ok
rascal>L = [];
list[void]: []

Taking the head of an empty list gives an error:

rascal>head(L);
|std:///List.rsc|(4590,9,<194,38>,<194,47>): EmptyList()
	at head(|std:///List.rsc|(4552,52,<194,0>,<194,52>))
	at $shell$(|prompt:///|(0,8,<1,0>,<1,8>))
 
ok

This is the case when taking the tail as well:

rascal>tail(L);
|std:///List.rsc|(17930,9,<785,44>,<785,53>): EmptyList()
	at tail(|std:///List.rsc|(17886,58,<785,0>,<785,58>))
	at $shell$(|prompt:///|(0,8,<1,0>,<1,8>))
 
ok

We can also catch the EmptyList error. First import the Rascal exceptions (which are also included in Prelude) and IO:

rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try
>>>>>>>  println(head(L));
>>>>>>>catch EmptyList():
>>>>>>>  println("Cannot take head of empty list");
Cannot take head of empty list
ok

1.5. Empty Map

Synopsis

Illegal operation on an empty map.

Types

data RuntimeException = EmptyMap();

Usage

import Exception; (only needed when EmptyMap is used in catch)

Description

Rascal provides many operations and functions on maps, see map values and map functions. This error is generated when a function or operations cannot handle the empty map case.

Remedies:

  • Guard the function or operation with a test on the empty map (isEmpty) and take alternative action in that case.

  • Catch the EmptyMap yourself, see try catch.

Examples

Import the Map library and introduce M with an empty map as value:

rascal>import Map;
ok
rascal>M = ();
map[void, void]: ()

Trying to get an arbitrary value from it gives an error:

rascal>getOneFrom(M);
|std:///Map.rsc|(2016,400,<94,0>,<111,41>): EmptyMap()
	at *** somewhere ***(|std:///Map.rsc|(2016,400,<94,0>,<111,41>))
	at getOneFrom(|prompt:///|(11,1,<1,11>,<1,12>))
 
ok

We can also catch the EmptyMap error. First import the Rascal exceptions (which are also included in Prelude) and IO:

rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try
>>>>>>>  println(getOneFrom(M));
>>>>>>>catch EmptyMap():
>>>>>>>  println("Cannot use getOneFrom on empty map");
Cannot use getOneFrom on empty map
ok

1.6. Empty Set

Synopsis

Illegal operation on an empty set.

Types

data RuntimeException = EmptySet();

Usage

import Exception; (only needed when EmptySet is used in catch)

Description

Rascal provides many operations and functions on sets, see set values and set functions. This error is generated when a function or operations cannot handle the empty set.

Remedies:

  • Guard the function or operation with a test on the empty set (isEmpty) and take alternative action in that case.

  • Catch the EmptySet yourself, see try catch.

Examples

Import the Set library and introduce S with an empty set as value:

rascal>import Set;
ok
rascal>S = {};
set[void]: {}

Taking an element from an empty set gives an error:

rascal>getOneFrom(S);
|std:///Set.rsc|(6658,381,<315,0>,<332,38>): EmptySet()
	at *** somewhere ***(|std:///Set.rsc|(6658,381,<315,0>,<332,38>))
	at getOneFrom(|prompt:///|(11,1,<1,11>,<1,12>))
 
ok

We can also catch the EmptySet error. First import the Rascal exceptions (which are also included in Prelude) and IO:

rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try
>>>>>>>  println(getOneFrom(S));
>>>>>>>catch EmptySet():
>>>>>>>  println("Cannot apply getOneFrom to empty set");
Cannot apply getOneFrom to empty set
ok

1.7. IO

Synopsis

An input/output operation caused an error.

Types

data RuntimeException = IO(str message);

Usage

import Exception; (only needed when IO is used in catch)

Description

This error can be generated for many reasons.

First there may be a problem in the location that is used. It maybe that the schemes is not supported. Examples of supported schemes include http, file, home, std, rascal and project. It can also be the case that the host that occurs in the location cannot be found.

Second, while trying to open the file things can go wrong like insufficient access rights

Finally, actual reading or writing can fail (device failure, device full, and the like).

Remedies:

  • Check for any errors in the location you are using.

  • Check that you are allowed to read or write the resource indicated by the location.

  • Catch IO using a try catch.

Examples

Import the IO library and attempt to use a non-existing scheme:

rascal>import IO;
ok
rascal>readFile(|myScheme:///example.rsc|);
|std:///IO.rsc|(12308,1718,<531,0>,<567,24>): IO("Unsupported scheme myScheme")
	at *** somewhere ***(|std:///IO.rsc|(12308,1718,<531,0>,<567,24>))
	at readFile(|prompt:///|(9,25,<1,9>,<1,34>))
 
ok

We can catch this IO error. First import the Rascal exceptions (which are also included in Prelude):

rascal>import Exception;
ok
rascal>try
>>>>>>>  readFileLines(|myScheme:///example.rsc|);
>>>>>>>catch IO(msg):
>>>>>>>  println("This did not work: <msg>");
This did not work: Unsupported scheme myScheme
ok

1.8. Index Out Of Bounds

Synopsis

Index is out of bounds.

Types

data RuntimeException = IndexOutOfBounds(int index)

Usage

import Exception; (only needed when IndexOutOfBounds is used in catch)

Description

Subscription is possible on various ordered types, including list, tuple, and node. This error is generated when a subscript is out of bounds for the value that is being subscripted.

Remedies:

  • Guard the subscription with a test that the index is within bounds.

  • Make your code less dependent on index values. Suggestions:

    • Use the index to produce all legal indices of a list. Instead of for(int i ← [0..size(L)]) { …​ } use for(int i ← index(L)) { …​ }.

    • Use a list slice to automate part of the index computation.

  • Catch the IndexOutOfBounds yourself, see try catch.

Examples

Initialize a list L:

rascal>L = [0, 10, 20, 30, 40];
list[int]: [0,10,20,30,40]

The legal indices are 0, 1, 2, 3, 4, so index 5 gives an error:

rascal>L[5];
|prompt:///|(2,1,<1,2>,<1,3>): IndexOutOfBounds(5)
	at $shell$(|prompt:///|(0,5,<1,0>,<1,5>))
 
ok

We can catch the IndexOutOfBounds error. First import the Rascal exceptions (which are also included in Prelude) and IO:

rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try
>>>>>>>  L[5];
>>>>>>>catch IndexOutOfBounds(msg):
>>>>>>>  println("The message is: <msg>");
The message is: 5
ok

1.9. Invalid Argument

Synopsis

A function or operation is applied to an invalid argument value.

Types

data RuntimeException = InvalidArgument() | InvalidArgument(value v) | InvalidArgument(value v, str message);

Usage

import Exception; (only needed when InvalidArgument is used in catch)

Description

This error is generated when a function or operation is applied to a value that it does not expect.

Remedies:

  • Check the value or values to which you apply the function or operation.

Examples

Changing the month of a DateTime to an illegal month (13):

rascal>NOW = $2013-01-13T22:16:51.740+01:00$;
datetime: $2013-01-13T22:16:51.740+01:00$
rascal>NOW.month = 13;
|prompt:///|(12,2,<1,12>,<1,14>): IllegalArgument(13,"Cannot create datetime with provided values.")
 
ok

Setting the offset in a location to a negative value:

rascal>someLoc = |home:///abc.txt|;
loc: |home:///abc.txt|
rascal>someLoc.offset = -1;
|prompt:///|(18,1,<1,18>,<1,19>): UnavailableInformation()
	at $shell$(|main://$shell$|)
 
ok

1.10. Invalid URI

Synopsis

An invalid URI is created at runtime.

Types

data RuntimeException = InvalidURI(str uri);

Usage

import Exception; (only needed when InvalidURI is used in catch)

Description

Thrown by operations on source locations that would lead to an invalid URI part of a source location value.

Examples
rascal>someLoc = |home:///abc.txt|;
loc: |home:///abc.txt|
rascal>someLoc.scheme = "a:b";
|prompt:///|(17,5,<1,17>,<1,22>): ParseError(|prompt:///|(17,5,<1,17>,<1,22>))
	at $shell$(|main://$shell$|)
 
ok

Another well-known example is a missing path when using // (wrong) instead of /// (good):

rascal>|home:///|;
loc: |home:///|
rascal>|home://|;
|prompt:///|(0,9,<1,0>,<1,9>): MalFormedURI("home://")
	at $shell$(|prompt:///|(0,10,<1,0>,<1,10>))
 
ok

1.11. Invalid Use Of Date

Synopsis

Invalid of of a date at runtime

Types

data RuntimeException = InvalidUseOfDate(str message);

Usage

import Exception; (only needed when InvalidUseOfDate is used in catch)

Description

Thrown by operations on date values that try to update unavailable information.

Examples

Setting the hour field on a date value throws an exception:

rascal>NOW = $2016-09-18$;
datetime: $2016-09-18$
rascal>NOW.hour = 14;
|prompt:///|(11,2,<1,11>,<1,13>): Can not retrieve the hour on a date value
Advice: |http://tutor.rascal-mpl.org/Errors/Static/UnsupportedOperation/UnsupportedOperation.html|
 
ok
Exception is not shown properly

1.12. Invalid Use Of Location

Synopsis

Invalid use of a source location at runtime.

Types

data RuntimeException = InvalidUseOfLocation(str message);

Usage

import Exception; (only needed when InvalidUseOfLocation is used in catch)

Description

Thrown by operations on source locations that would lead to an inconsistent or incomplete location value.

Examples
rascal>someLoc = |home:///abc.txt|;
loc: |home:///abc.txt|
rascal>someLoc.begin = <1, 2>;
|prompt:///|(20,1,<1,20>,<1,21>): UnavailableInformation()
	at $shell$(|main://$shell$|)
 
ok

1.13. Invalid Use Of Time

Synopsis

Invalid use of a time value at runtime

Types

data RuntimeException = InvalidUseOfTime(str message);

Usage

import Exception; (only needed when InvalidUseOfTime is used in catch)

Description

Thrown by operations on time values that try to update unavailable information.

Examples

Setting the year field on a time value throws an exception:

rascal>NOW = $T20:11:01.463+00:00$;
|prompt:///|(6,21,<1,6>,<1,27>): Invalid datetime input: Error reading time, expected ':', found: 49
Advice: |http://tutor.rascal-mpl.org/Errors/Static/DateTimeSyntax/DateTimeSyntax.html|
 
ok
rascal>NOW.year = 2020;
|prompt:///|(0,3,<1,0>,<1,3>): Undeclared variable: NOW
Advice: |http://tutor.rascal-mpl.org/Errors/Static/UndeclaredVariable/UndeclaredVariable.html|
 
ok
Exception is not shown properly

1.14. Java

Synopsis

Runtime error generated by Java code.

Description

This error is generated when an unexpected Java execption is thrown in the Rascal implementation.

Remedy: Contact the Rascal developers:

If you are an expert developer and have implemented your own extension in Java, please check your own extension code first.

1.15. No Main Function

Synopsis

Rascal program does not provide a main function.

Types

data RuntimeException = NoMainFunction(str message);

Usage

import Exception; (only needed when NoMainFunction is used in catch)

Description

Thrown when executing a Rascal program that does not declare a main function.

1.16. No Parent

Synopsis

Parent directory is missing in source location.

Types

data RuntimeException = NoParent(loc noparentloc);

Usage

import Exception; (only needed when NoParent is used in catch)

1.17. No Such Annotation

Synopsis

Annotation without a value.

Types

data RuntimeException = NoSuchAnnotation(str label);

Usage

import Exception; (only needed when NoSuchAnnotation is used in catch)

Description

An annotation can be associated with any node value (including any algebraic data type). This error is generated when the value of an annotation is requested but has not been defined.

Remedies:

  • Ensure that the annotation value is properly initialized for all relevant parts of the node value.

  • Use the isDefined and ifDefinedElse operators to check whether the annotation value is set and act accordingly.

  • Catch the NoSuchAnnotation yourself, see try catch.

Examples

INFO: Eliminate the double Error: Error:

rascal>data Fruit = apple(int n) | orange(int n);
ok
rascal>anno str Fruit @ quality;
ok
rascal>piece = orange(13);
Fruit: orange(13)
rascal>piece@quality;
|prompt:///|(0,5,<1,0>,<1,5>): NoSuchAnnotation("quality")
	at $shell$(|prompt:///|(0,14,<1,0>,<1,14>))
 
ok

Use the unary postfix operator isDefined ? to check whether the quality annotation is set:

rascal>piece@quality?;
bool: false

Use the ternary operator ifDefinedElse ? to compute an alternative value when the quality annotation is not set:

rascal>piece@quality ? "no quality value";
str: "no quality value"

We can also catch the NoSuchAnnotation error. First import the Rascal exceptions (which are also included in Prelude) and IO:

rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try piece@quality; catch NoSuchAnnotation(l): println("No such annotation: <l>");
No such annotation: quality
ok

Finally, we can just assign a value to the quality annotation:

rascal>piece@quality = "excellent";
Fruit: orange(13,quality="excellent")
rascal>piece@quality;
str: "excellent"
Pitfalls
Using white space around the @ confuses the Rascal parser

1.18. No Such Field

Synopsis

Field of an abstract data type value cannot be found at runtime.

Types

data RuntimeException = NoSuchField(str name);

Usage

import Exception; (only needed when NoSuchField is used in catch)

Description

Selecting a field from an abstract datatype depends on the actual constructor being used at run time. This exception is thrown when a non-existent field is accessed.

Examples

Consider this highly simplified view on persons:

rascal>data Person = man(str name, bool beard) | woman(str name, bool necklace);
ok
rascal>jane = woman("jane", false);
Person: woman("jane",false)

The field beard is evidently only applicable to a man but not to a woman (didn’t we say "simplified", above):

rascal>jane.beard;
|prompt:///|(0,4,<1,0>,<1,4>): NoSuchField("beard")
 
ok

1.19. No Such Key

Synopsis

A map does not contain a requested key.

Types

data RuntimeException = NoSuchKey(value v);

Usage

import Exception; (only needed when NoSuchKey is used in catch)

Description

Rascal provides many operations and functions on maps, see map values and map functions. This error is generated when a function or operation cannot find a requested key value in a map.

Remedies:

Examples

Import the Map and IO libraries and introduce map M:

rascal>import Map;
ok
rascal>import IO;
ok
rascal>M = ("a" : 1, "b" : 2);
map[str, int]: ("a":1,"b":2)

Indexing M with a non-existing key gives an error:

rascal>M["c"]
|prompt:///|(2,3,<1,2>,<1,5>): NoSuchKey("c")
	at $shell$(|prompt:///|(0,23,<1,0>,<1,23>))
 
ok

Use the postfix isDefined operator ? to test whether the value is defined:

rascal>if(M["c"]?) println("defined"); else println("not defined");
not defined
ok

Or use the binary ifDefinedElse operator ? to return an alternative value when the value of M["c"] is undefined:

rascal>M["c"] ? 3
int: 3

Yet another solution is to use try/catch. First we import the Rascal exceptions (which are also included in Prelude):

rascal>import Exception;
ok
rascal>try println(M["c"]); catch NoSuchKey(k): println("Key <k> does not exist");
Key c does not exist
ok

1.20. Not Implemented

Synopsis

Attempt to execute an unimplemented feature.

Types

data RuntimeException = NotImplemented(str msg), loc src);

Usage

import Exception; (only needed when NotImplemented is used in catch)

Description

Thrown when a not (yet) implemented feature is executed. This exception is mostly used by the Rascal implementors.

1.21. Parse Error

Synopsis

Parse of a syntactically incorrect string.

Types

data RuntimeException = ParseError(loc parseloc) | ParseError(loc parseloc, str nt, str s);

Usage

import Exception; (only needed when ParseError is used in catch)

Description

This error is generated when during the execution of a Rascal program the parse function is applied to a syntactically incorrect input sentence.

Remedies:

  • Correct the input sentence.

  • Adapt the grammar so that it accepts the input sentence.

  • Catch the ParseError yourself, see try catch.

Examples

Define the non-terminal As that accepts one or more letters a:

rascal>syntax As = "a"+;
ok

Then import ParseTree so that we can use the parse function:

rascal>import ParseTree;
ok

Now we can parse sentences consisting of letters a:

rascal>parse(#As, "aaaaaaaa");
As: (As) `aaaaaaaa`

But we get an error when parsing syntactically incorrect input (i.e., that does not consists of letters a only):

rascal>parse(#As, "aaaabaaa");
|TODO:///|: ParseError(|unknown:///|(4,1,<1,4>,<1,5>))
 
ok

We can also catch the ParseError but first import the Rascal modules Exception and IO:

rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try
>>>>>>>  parse(#As, "aaaabaaa");
>>>>>>>catch ParseError(e):
>>>>>>>  println("Your input cannot be parsed: <e>");
Your input cannot be parsed: |unknown:///|(4,1,<1,4>,<1,5>)
ok

1.22. RegExp Syntax Error

Synopsis

Syntax error in regular expression at run time

Types

data RuntimeException = RegExpSyntaxError(str message);

Usage

import Exception; (only needed when RegExpSyntaxError is used in catch)

Description

At the moment, the parsing and compilation of regular expression is done at run time. This exception is thrown when a syntactically incorrect regular expression is used.

Examples

The following regular expression /+/ is incorrect (maybe /a+/ was meant?):

rascal>/+/ := "aaaa";
|prompt:///|(7,6,<1,7>,<1,13>): Syntax error: Dangling meta character '+' near index 0
+
^
Advice: |http://tutor.rascal-mpl.org/Errors/Static/SyntaxError/SyntaxError.html|
 
ok

1.23. Unavailable Information

Synopsis

Requested information is unavailable at runtime

Types

data RuntimeException = UnavailableInformation(str message);

Usage

import Exception; (only needed when UnavailableInformation is used in catch)

Description

Several datetypes may contain optional information that is not always available:

  • In a datetime value the date or the time may be missing.

  • In a location value, various fields are optional, e.g., port, offset, begin and end.

This exception is thrown when optional information is not available.

Examples
rascal>$2016-09-14$.hour;
|prompt:///|(0,12,<1,0>,<1,12>): Can not retrieve the hour on a date value
Advice: |http://tutor.rascal-mpl.org/Errors/Static/UnsupportedOperation/UnsupportedOperation.html|
 
ok
rascal>someLoc = |home:///abc.txt|;
loc: |home:///abc.txt|
rascal>someLoc.offset;
|prompt:///|(0,7,<1,0>,<1,7>): UnavailableInformation()
	at $shell$(|prompt:///|(0,15,<1,0>,<1,15>))
 
ok

2. Other Runtime Errors

Synopsis

Other runtime errors that cannot be caught as a runtime exception.

Description

Note: Examples will be collected here

2.1. Compiler Error

Synopsis

An internal error in the Rascal compiler

Description

An internal error condition occurred while running the Rascal compiler. This exception may be generated due to:

  • An actual internal inconsistency.

  • Incorrect information as computed by the type checker.

  • Incorrect configuration of paths (PathConfig) when calling the compiler.

  • Causes outside control of the compiler.

Pitfalls

At the moment this error category is too wide and should be narrowed.