Visual C++: Exemple de gestion des exceptions

Author:


Download

#include "stdafx.h"

using namespace System;


Int32 main(void)
{
   String ^ y = gcnew String("abc");
	int x=0;

    try
    {
		 // Convetir le string en Int
        x = Convert::ToInt32(y); // Générer l'exception
         Console::WriteLine("No Exception");  // cette ligne ne sera pas exécutée
		 	
    }
    catch (Exception ^e)
    {
        Console::WriteLine("Invalid Cast Exception");
        Console::WriteLine(e->StackTrace);
    }

	Console::ReadLine();
    return 0;
}


Leave a Reply

Your email address will not be published. Required fields are marked *