¿Qué sucede si tanto la captura y finalmente bloques lanzar excepción?
¿Qué sucede si la excepción catch y finalmente los bloques throw?
5 answers
Cuando el bloque finally
lanza una excepción, ocultará efectivamente la excepción lanzada del bloque catch
y será la que finalmente se lance. Por lo tanto, es importante registrar excepciones cuando se detecta, o asegurarse de que el bloque finally no arroje una excepción, de lo contrario puede obtener excepciones que se lanzan que se sofocan y nunca se ven.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-09-26 23:32:50
Cuando catch lanza una excepción, finalmente se ejecutará block y luego se saldrá con una excepción. Si el bloque finalmente lanza una excepción, el bloque saldrá con una excepción.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-09-26 23:26:29
La última excepción lanzada es lanzada.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-09-26 23:25:45
Ya ha sido contestado bien por adrianbanks, pero el siguiente post debería ser interesante: Interesantes Resultados de Excepciones: Lanzar Excepciones Desde el Bloque Finally
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-09-26 23:34:29
HOLA Nwaman creo que tu respuesta es incorrecta lo he probado en windows appliaction, encontré si escribes un programa como el siguiente
try
{
string s = "hu";
int i = int.Parse(s);
}
catch (Exception ex)
{
string s = "hu";
int i = int.Parse(s);
throw new Exception();
}
finally
{
MessageBox.Show("hi");
}
Y esto no resultará finalmente a excute,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-10-22 09:57:57