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