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 Campo Tipo Descrizione .causeerror L'errore che ha portato a questo, oppure null. .columnnumber La colonna da cui proviene l'errore. .filestring Lo script da cui proviene l'errore. .linenumber La riga da cui proviene l'errore. .messagestring Che cosa è andato storto. .statusnumber Lo stato HTTP associato al suo tipo di errore, come 404, oppure null. .typestring Il 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
.kscript XML Copia
<error name="PersonNotFound" extends="NotFound" />
<try>
<throw value="PersonNotFound()" />
<catch as="err"><echo>{ $err->chain() }</echo></catch>
</try>.kscript XML Copia
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
.kscript XML Copia
<try>
<throw value="FileNotFound('No settings.json')" />
<catch as="err"><echo>{ $err->is(IO) }</echo></catch>
</try>.kscript XML Copia
try {
throw FileNotFound('No settings.json')
} catch err {
echo $err->is(IO)
}Metodi da any