Error Handling
Catch runtime errors with tijaabi and qabo, understand Somali diagnostics, and look up error codes and source locations.
Error Handling in Soplang
An uncaught runtime error, such as division by zero, stops the program. Use
tijaabi and qabo to catch an error and continue execution.
tijaabi and qabo – Try / Catch
Place code that may fail inside a tijaabi block. If an error occurs, execution
transfers to qabo. The variable in qabo (...) receives the error message
as a string (qoraal).
hawl qaybi(a, b) { celi a / b } tijaabi { qor(qaybi(10, 2)) // 5 qor(qaybi(10, 0)) // Error: transfers control to qabo qor("Tan lama gaaro") } qabo (khalad) { qor("Qabtay: " + khalad) // Qabtay: Tiro looma qaybin karo eber. qor(nooc(khalad)) // qoraal } qor("Barnaamijku wuu sii socdaa")
- A
tijaabiblock needsqabo,dhammee, or both. - If no error occurs, the
qaboblock is skipped. - Try blocks can be nested. The nearest enclosing
qabocatches an error.
tijaabi { tijaabi { qor(1 / 0) } qabo (gudaha) { qor("gudaha: " + gudaha) } qor("kadib") } qabo (dibadda) { qor("dibadda") }
Catchable runtime errors
tijaabi catches errors from built-ins, methods, callbacks, and division by zero. A callback error stops iteration and propagates to the nearest qabo. Lexer, parser, and analysis errors occur before execution and cannot be caught this way.
Raising errors and cleanup
tuur raises a string or a structured khalad value. The first qabo
binding receives the message; an optional second binding receives the error
with .fariin, .summad, and .sabab fields. dhammee runs when the
protected block exits, including after an error or return.
tijaabi { tuur khalad("Xogtu ma dhammaystirna", "XOG001") } qabo (fariin, xog) { qor(fariin, xog.summad) } dhammee { qor("Hawshii waa dhammaatay") }
The khalad(fariin, summad?, sabab?) constructor creates an error value
without raising it. Errors can be chained through .sabab. An uncaught error
includes a source location and call trace. See the
language reference
for rethrowing and cleanup rules.
Error Messages
Soplang's diagnostic output is in Somali. The following examples preserve the actual message format:
Khalad <nooc>: <fariin> [<code>] safka <sadar>, tiirka <tiir>
--> <fayl>:<sadar>:<tiir>For example, reassigning a madoor constant produces:
Khalad nooc: Ma bedeli kartid qiimaha doorsamaha madoor 'luqad' [E020] safka 2, tiirka 1
--> luqad.sop:2:1
2 │ luqad = "English"
│ ^^^^^
└─ Doorsamaha madoor ma beddeli karaan qiimahooda. Isticmaal 'door' haddii aad rabto mid beddeli kara.Diagnostic categories (<nooc> in the format above) identify the phase:
| Category | Meaning |
|---|---|
ereyayn | Lexing: an unknown character, unclosed string, or unclosed comment |
naxwe | Parsing: invalid syntax, such as a missing ) or } |
nooc | A type or declaration error |
fulin | A runtime error, such as division by zero |
soo-dejin | An import error, such as a missing file named by keen |
Disable diagnostic colors with --no-color or NO_COLOR=1.
Error Codes
Some diagnostics include a short code:
| Code | Meaning |
|---|---|
E001 | Unexpected character |
E002 | Unclosed string |
E003 | Unclosed /* */ comment |
E020 | Redeclaration or reassignment of a madoor constant |
E021 | Missing item, such as an imported file |
E022 | Type mismatch in an assignment, function argument, or return value |
Source Context and Exit Status
Uncaught failures write Somali diagnostics to stderr and exit with status 1.
Source diagnostics include the source file, line, column, source line and caret.
Infrastructure errors without a source location omit line and column numbers. Columns
count Unicode scalar values; caret spacing accounts for tabs, combining marks
and wide characters. Imported files retain their own source context. LLVM-built
executables retain relevant source lines even when the original files are gone.
Caught errors are message strings, not structured error objects or stack traces.
fasax remains a compatible try spelling; new examples use tijaabi.
CLI argument errors, such as unknown flags or missing values, use Somali
explanations and exit with status 2. --help and --version exit with status 0.
File and tool failures retain exit status 1.
Set SOPLANG_ERROR_DETAILS=1 to include original external tool or OS messages
under Faahfaahin farsamo: on stderr. These optional details can be English.
They are separate from the primary diagnostic and never become part of the
message string received by qabo. The setting also works in LLVM-built
executables; their normal runtime error messages remain Somali.