Beispiel #1
0
        /// <summary>
        /// Wrap function call with handled exceptions
        /// </summary>
        /// <param name="deleg"></param>
        /// <returns></returns>
        public static ExceptionHandlerResponse HandledFunctionCall(ExcpentionDelegate deleg)
        {
            ExceptionHandlerResponse response = null;
            string message = "";
            string originalMessage = "";

            try
            {
                deleg();
            }
            catch (FormatException ex)
            {
                Helpers.Logger.LogError(ex.Message, ex.StackTrace);
                message = Properties.Resources.Error_Format;
            }
            catch (SqlException ex)
            {
                //Some kind of problem with sql, log it.
                Helpers.Logger.LogError(ex.Message, ex.StackTrace);
                message = Properties.Resources.Error_Saving;
            }
            catch (Exception ex)
            {
                //Generic exception, log it.
                Helpers.Logger.LogError(ex.Message, ex.StackTrace);
                originalMessage = ex.Message;
                message = Properties.Resources.Error_Saving;
            }
            finally
            {
                response = new ExceptionHandlerResponse(message != "" ? true : false, message, originalMessage);
            }

            return response;
        }
Beispiel #2
0
        /// <summary>
        /// Wrap function call with handled exceptions
        /// </summary>
        /// <param name="deleg"></param>
        /// <param name="infoLabel"></param>
        /// <param name="errorMessage"></param>
        public static void HandledFunctionCall(ExcpentionDelegate deleg, Label infoLabel, string errorMessage)
        {
            ExceptionHandlerResponse response = HandledFunctionCall(deleg);

            if (response.ExceptionCaught)
            {
                infoLabel.ForeColor = Color.Red;
                infoLabel.Text = errorMessage;
            }
        }