GPPointFileInfo\GPException.cs
Creating a non-trival custom GP tool - inputs, outputs, and responding to environment settings
GPPointFileInfo\GPException.cs
// Copyright 2008 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See use restrictions at <your ArcGIS install location>/developerkit/userestrictions.txt.
// 

using System;

namespace GPPointFileInfo
{
    public class GPException : ApplicationException
    {
        private GPExceptionSeverity _exceptionSeverity;

        public GPException(GPExceptionSeverity exceptionSeverity, string message)
            : base(message)
        {
            _exceptionSeverity = exceptionSeverity;
        }

        public GPException(GPExceptionSeverity exceptionSeverity, string message, Exception innerException)
            :base(message, innerException)
        {
            _exceptionSeverity = exceptionSeverity;
        }

        public void LogException(IGPMessages gpMessages)
        {
            string message = GetMessage();

            switch (_exceptionSeverity)
            {
                case GPExceptionSeverity.Warn:
                    gpMessages.AddWarn(message) ;
                    break;

                case GPExceptionSeverity.Error:
                    gpMessages.AddError(message);
                    break;

                case GPExceptionSeverity.Fatal:
                    gpMessages.AddFatal(message);
                    break;
            }
        }

        private string GetMessage()
        {
            string message = "\n" + this.Message;

            if (this.InnerException != null)
            {
                message += "" + this.InnerException.Message;
            }

            message += "\n";

            return message;
        }
    }
}