-
Notifications
You must be signed in to change notification settings - Fork 0
throw
ffredyk edited this page Jul 23, 2026
·
1 revision
Error Handling
Unary — throw <value>.
throw <any>
Throws an error with the given value. If inside a try block, execution jumps to the corresponding catch block with the thrown value available as _exception. If not inside a try block, the fiber terminates with an error.
The compiler emits a throw opcode. The VM unwinds the execution stack to the nearest enclosing try/catch. If no try block is found, the fiber is terminated and the error propagates to the fiber's ScriptHandle.
The caught error is an SqError object with properties:
-
.message— the thrown value as string -
.file— source file -
.line— line number -
.col— column number
try {
if (_hp <= 0) then { throw "Unit is dead"; };
doWork();
} catch (_error) {
systemChat f"Error: {_error}";
};try {
if (_index < 0) then { throw ["out_of_range", _index]; };
} catch (_err) {
_err params ["_code", "_detail"];
systemChat f"Error {_code}: {_detail}";
};_validatePositive = {
params ["_val", "_name"];
if (_val < 0) then {
throw f"{_name} must be positive, got {_val}";
};
};
try {
[_hp, "HP"] call _validatePositive;
[_armor, "Armor"] call _validatePositive;
} catch (_error) {
systemChat f"Validation failed: {_error}";
};_handle = spawn {
throw "Something went wrong";
systemChat "Never reached";
};
// The handle resolves with an error — await will return nilThrowing unwinds the current fiber only. Other fibers are unaffected. The SqError object is owned by the catching fiber.
- try/catch — error handling construct
- Getting Started
- Language Guide
- Type System
- Control Flow
- Functions & Code
- Strings & Text
- Arrays & Collections
- Concurrency
- Promise System
- Thread Safety
- Host API & Embedding
- CLI Tool
- Bytecode Reference
- Multiplayer
- Syntax Sugar
- Optimization Guide
- Benchmarks
- count
- select
- pushBack
- append
- deleteAt
- deleteRange
- resize
- reverse
- sort
- find
- in
- forEach
- freeze
- thaw
- isFrozen
- currentScheduler
- clientOwner
- allSchedulers
- schedulerName
- schedulerExists
- schedulerBudget
- setSchedulerBudget
- fiberCount
- readyFiberCount
- waitingFiberCount
- schedulerLoad
- sendTo