Try / Catch con javascript

Con javascript è possibile utilizzare l’istruzione TRY / CATCH per poter catturare i messaggi di errore che compaiono.

Il codice che permette ciò è il seguente:

function … {

try {

catch(err) {
txt=”There was an error on this page.\n\n”
txt+=”Error description: ” + err.description + “\n\n”
txt+=”Click OK to continue.\n\n”
alert(txt)
}
}

Nel modo descritto, se c’è un’errore nel codice all’interno del TRY, viene catturato e visualizzato nell’alert.

Posted by admin on febbraio 14th, 2010 | 1 Comment » | Javascript | RSS 2.0

One Response to “Try / Catch con javascript”

Leave a Reply