KScript documentazione
IT

Lingua

Tradotto automaticamente dall’inglese, che è la versione originale.

campi e metodi di error

Un campo è un dato semplice sul valore, letto con un punto e senza parentesi: $value.name. Un metodo richiede argomenti o esegue un'operazione, e si chiama con ->: $value->name(arguments), oppure passando il valore con la pipe: $value |> name(arguments).

Campi

CampoTipoDescrizione
.causeerrorL'errore che ha portato a questo, oppure null.
.columnnumberLa colonna da cui proviene l'errore.
.filestringLo script da cui proviene l'errore.
.linenumberLa riga da cui proviene l'errore.
.messagestringChe cosa è andato storto.
.statusnumberLo stato HTTP associato al suo tipo di errore, come 404, oppure null.
.typestringIl tipo di errore, come FileNotFound.

Da KScript.Core

#error->chain() → list

Il tipo di errore e i tipi che estende, dal più vicino: ['NotFound', 'Validation', 'Error'].
Esempio
<error name="PersonNotFound" extends="NotFound" />
<try>
  <throw value="PersonNotFound()" />
  <catch as="err"><echo>{ $err->chain() }</echo></catch>
</try>
error PersonNotFound extends NotFound
try {
  throw PersonNotFound()
} catch err {
  echo $err->chain()
}

#error->is(type) → bool

Vero quando l'errore è di questo tipo o di un tipo che lo estende: $err->is(NotFound), $err->is(IO).
Esempio
<try>
  <throw value="FileNotFound('No settings.json')" />
  <catch as="err"><echo>{ $err->is(IO) }</echo></catch>
</try>
try {
  throw FileNotFound('No settings.json')
} catch err {
  echo $err->is(IO)
}

Metodi da any