WCM - Das österreichische Computer Magazin Forenübersicht
 

Zurück   WCM Forum > Rat & Tat > Programmierung

Programmierung Rat & Tat für Programmierer

Microsoft KARRIERECAMPUS

 
 
Themen-Optionen Ansicht
Alt 23.12.2003, 10:55   #1
Biri
Hero
 
Registriert seit: 04.09.2001
Beiträge: 894


Standard try, catch, ...finally

hi !

Ich lese im moment gerade eine paar prüfungsbeispiele für den MCAD.
Dort gibt es folgendes Beispiel:

try
{
Debug.WriteLine(“Inside Try”);
throw(new IOException());
}
catch (IOException e)
{
Debug.WriteLine (“IOException Caught”);
}
catch (Exception e)
{
Debug.WriteLine(“Exception Caught”);
}
finally
{
Debug.WriteLine (“Inside Finally”);
}
Debug.WriteLine (“After End Try”);


Welche Ausgabe erzeugt der code ?

A.
Inside Try
Exception Caught
IOException Caught
Inside Finally
After End Try

B.
Inside Try
Exception Caught
Inside Finally
After End Try

C.
Inside Try
IOException Caught
Inside Finally
After End Try

D.
Inside Try
IOException Caught
Inside Finally

Antowrt: D

Explanation: First the try code runs. Then one single exception occurs, not two.
Then the finally code is run, and not the code after finally.

Reference: 70-306/70-316 Training kit, Creating an Exception handler, page 235

Incorrect Answers
A: An exception can only be caught once, not twice.
B: The code after finally will not be run if an exception occurs.
C: The code after finally will not be run if an exception occurs.

Das stimmt aber nicht !
Wenn man das Beispiel im VS.Net ausprobiert, wird der code NACH finally immer ausgeführt.
Dadurch stellt sich dann aber die frage: wozu benötigt man finally überhaupt ??

Was sagt Ihr dazu ?

fg
-hannes
Biri ist offline   Mit Zitat antworten
 


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 09:11 Uhr.


Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Forum SEO by Zoints
© 2009 FSL Verlag