← SPL reference

Errors & exceptions

Typed runtime errors implement SPLException with a .kind string. You can catch them with structured try/except in SPL.

error.try():
  # risky code
end;
error.except(error.DivisionByZeroError):
  # handler
end;

Handlers are merged when error.try(): is immediately followed by one or more error.except(...): blocks. String literals can match .kind as well.

Stack traces

Uncaught errors print an SPL call stack (most recent call last) when the failure happened inside a user function, instance method, or used module. Example shape:

Error: [Line 12] DivisionByZeroError: division by zero
SPL stack (most recent call last):
  line 4: module /path/to/helper.spl
  line 12: function boom

Raise your own typed errors with error.raise(error.SomeKind, "message") (after errorDefine if custom).