// CtorTest.cpp : main project file.

#include "stdafx.h"

using namespace System;

ref class Test
{
    String^ pv;
public:
    Test(String^ pval)
    {
		// test for null pointer or empty string
        if (pval == nullptr || pval == L"")
            throw gcnew System::ArgumentException(
               L"Argument null or blank");
        else
            pval = pv;
    }
};

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Exceptions in Constructors");
    // Create a null pointer to test the exception handling
    String^ ps = L"Some test string";
    Test^ pt = nullptr;

    // Try creating an object
    try
    {
        pt = gcnew Test(ps);
    }
    catch(System::ArgumentException^ pex)
    {
        Console::WriteLine(L"Exception: {0}", pex->Message);
    }
    Console::WriteLine(L"Object construction finished");
    return 0;
}