View Full Version : [C#] codice errore
CL4UD1O83
09-10-2008, 14:36
ciao a tutti,
guardando qua è là in rete ho trovato che quando un programma genera un'eccezione è possibile visualizzare un codice associato all'errore, qualcuno mi sa dire come si fa please?
grazie in anticipo
||ElChE||88
09-10-2008, 16:12
try
{
// Codice che genera l'eccezione
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
CL4UD1O83
09-10-2008, 16:42
try
{
// Codice che genera l'eccezione
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
uso già le istruzioni try e catch con MessageBox.Show anzichè Console.Writeline ma queste mi restituiscono solo il tipo di eccezione cioè ad esempio NullReferenceException o StackOverflowException in realtà ho visto che, per lo meno nel caso dei socket, si può avere un codice errore numerico e su msdn viene spiegata la causa dell'errore...
RaouL_BennetH
10-10-2008, 10:05
Ciao :)
Credo dipenda dal tipo di eccezione che vai a gestire.
Tu citavi i socket, ad esempio credo che si possa fare una cosa del genere:
using System.Net;
using System.Net.Sockets;
try
{
//codice
}
catch(SocketException ex)
{
MessageBox.Show(ex.SocketErrorCode);
}
Ciao :)
CL4UD1O83
10-10-2008, 11:31
Ciao :)
Credo dipenda dal tipo di eccezione che vai a gestire.
Tu citavi i socket, ad esempio credo che si possa fare una cosa del genere:
using System.Net;
using System.Net.Sockets;
try
{
//codice
}
catch(SocketException ex)
{
MessageBox.Show(ex.SocketErrorCode);
}
Ciao :)
ok, grazie mille! il mio errore è 10061: "connection refused"...
solo una precisazione il codice è:
using System.Net;
using System.Net.Sockets;
try
{
//codice
}
catch(SocketException ex)
{
MessageBox.Show(ex.ErrorCode.ToString());
}
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.