Soplang Logo
Soplang

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).

try_catch.sop
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 tijaabi block needs qabo, dhammee, or both.
  • If no error occurs, the qabo block is skipped.
  • Try blocks can be nested. The nearest enclosing qabo catches an error.
nested_try.sop
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.

raise_cleanup.sop
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:

CategoryMeaning
ereyaynLexing: an unknown character, unclosed string, or unclosed comment
naxweParsing: invalid syntax, such as a missing ) or }
noocA type or declaration error
fulinA runtime error, such as division by zero
soo-dejinAn 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:

CodeMeaning
E001Unexpected character
E002Unclosed string
E003Unclosed /* */ comment
E020Redeclaration or reassignment of a madoor constant
E021Missing item, such as an imported file
E022Type 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.

On this page