![]() |
|
Navigation |
Synopsis An input/output operation caused an error.
Function
data RunTimeException = IO(str message);
Usage
import Exception;
Description This error can be generated for many reasons.
First there may be a problem in the Rascal: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:
Examples Import the
IO library and attempt to use a non-existing scheme:
rascal>import IO; ok rascal>readFile(|myScheme:///example.rsc|); |rascal://IO|(10727,1709,<433,0>,<466,43>): IO("Unsupported scheme myScheme") at *** somewhere ***(|rascal://IO|(10727,1709,<433,0>,<466,43>)) at readFile(|stdin:///|(9,25,<1,9>,<1,34>))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 ![]() |