// OwnExcept.cpp : main project file.

#include "stdafx.h"

using namespace System;

// User-defined exception class
ref class MyException : public System::Exception
{
	public:
		int errNo;
		MyException(String^ msg, int num) : Exception(msg), errNo(num) {}
};

void func(int a)
{
    try
    {
        if (a <= 0)
            throw gcnew System::ArgumentException(
               L"Negative argument");
    }
    catch(System::ArgumentException^ pex)
    {
        Console::WriteLine(L"Caught ArgumentException"
                L"in func()");
        throw gcnew MyException(pex->Message, 1000);
    }
}

int main(array<System::String ^> ^args)
{
	Console::WriteLine(L"Custom Exceptions");
    try
    {
        func(0);
    }
    catch(MyException^ pex)
    {
        Console::WriteLine(L"Caught MyException in main()");
        Console::WriteLine(L"Message is : {0}", pex->Message);
        Console::WriteLine(L"Error number is : {0}", (Object ^)(pex->errNo));
    }
    return 0;
}

