Exceptions
All languages have some way of representing a breaking error state, or exception, that indicates control flow must be halted. Exceptions may be created and thrown, also known as raised, and later caught, also known as rescued, by some calling code. Budgie refers to these operations as catching and throwing exceptions.

Throwing

The built-in exception class for an output language is represented in Budgie by the exception command, which receives a single string as input. It can be thrown with the throw command.
1
throw : { exception } ("Oh no!")
Copied!
In C#:
1
throw new Exception("Oh no!");
Copied!
In Python:
1
raise Exception("Oh no!")
Copied!

Catching

All supported languages have some variant of the following three code blocks:
    Try: runs some code that might throw an error
    Catch: handles any error thrown by the try section
    Finally: runs regardless of whether an error was thrown
Each of these are considered their own distinct blocks with a start and end in Budgie. The catch section also takes in the name of a general exception.
1
try start
2
throw : { exception } ("Oh no!")
3
try end
4
catch start : error
5
print : ("Found an error.")
6
catch end
7
finally start
8
comment line : ...
9
finally end
Copied!
In C#:
1
try
2
{
3
throw new Exception("Oh no!");
4
}
5
catch (Exception error)
6
{
7
Console.WriteLine("Found an error.");
8
}
9
finally
10
{
11
// ...
12
}
Copied!
In Python:
1
try:
2
raise Exception("Oh no!")
3
except Exception as error:
4
print("Found an error.")
5
finally:
6
# ...
Copied!
Last modified 1yr ago
Copy link