#include "stdafx.h" using namespace System; ref class X {}; ref class Y {}; void main() { X ^x = gcnew X; try { Y ^y = (Y^)x; Console::WriteLine("No Exception"); } catch (InvalidCastException ^e) { Console::WriteLine("Invalid Cast Exception"); Console::WriteLine(e->StackTrace); } }