public ExceptionInfoResponseBody(string exceptionId, ExceptionBreakMode breakMode, string description = null, ExceptionDetails details = null)
 {
     this.ExceptionId = exceptionId;
     this.BreakMode   = breakMode;
     this.Description = description;
     this.Details     = details;
 }
        private bool shouldThrow(string exceptionId, ExceptionBreakMode breakMode)
        {
            string[] parts    = exceptionId.Split('/');
            string   category = parts.First();
            string   name     = parts.Last();

            ExceptionCategorySettings settings = null;

            if (!this.exceptionCategorySettings.TryGetValue(category, out settings))
            {
                // No configuration for this category - just send it to the host
                return(true);
            }

            ExceptionBreakMode settingMode = settings.GetExceptionBreakMode(name);

            if (settingMode == ExceptionBreakMode.Always)
            {
                // Host always wants this exeception
                return(true);
            }
            else if (settingMode == ExceptionBreakMode.Unhandled && breakMode == ExceptionBreakMode.Unhandled)
            {
                // Host wants this exception if it's unhandled
                return(true);
            }
            else if (settingMode == ExceptionBreakMode.UserUnhandled && (breakMode == ExceptionBreakMode.Unhandled || breakMode == ExceptionBreakMode.UserUnhandled))
            {
                // Host wants this exception if it's not handled by the user
                return(true);
            }

            return(false);
        }
 public ExceptionOptions(ExceptionBreakMode breakMode, ExceptionPathSegment[] path = null)
 {
     Path      = path;
     BreakMode = breakMode;
 }
 internal void SetExceptionBreakMode(string exception, ExceptionBreakMode breakMode)
 {
     this.exceptionSettings.Add(exception, breakMode);
 }
        private bool DoThrow(ThrowArgs args, StringBuilder output)
        {
            SampleThread thread = this.adapter.ThreadManager.GetThread(args.ThreadId);

            if (thread == null)
            {
                output.AppendLine(Invariant($"Unknown thread id '{args.ThreadId}'!"));
                return(false);
            }

            if (this.HasPendingException)
            {
                output.AppendLine("Exception is already pending!");
                return(false);
            }

            if (!args.ExceptionId.Contains("/"))
            {
                output.AppendLine("Expected ExceptionId to be of form 'Category/Exception'!");
                return(false);
            }

            ExceptionBreakMode breakMode = ExceptionBreakMode.Always;

            if (args.Type != null)
            {
                switch (args.Type.Value)
                {
                case ExceptionType.Caught:
                    breakMode = ExceptionBreakMode.Always;
                    break;

                case ExceptionType.Uncaught:
                    breakMode = ExceptionBreakMode.Unhandled;
                    break;

                case ExceptionType.UserUncaught:
                    // UserUncaught means the exception was caught in non-user code, so if JMC is turned off, treat it like any other
                    //  caught exception.
                    breakMode = (this.adapter.IsJustMyCodeOn ?? false) ? ExceptionBreakMode.UserUnhandled : ExceptionBreakMode.Always;
                    break;
                }
            }

            if (this.shouldThrow(args.ExceptionId, breakMode))
            {
                // Our configuration includes this exception - report it to the host
                this.PendingExceptionThread = args.ThreadId;
                this.pendingException       = new ExceptionInfoResponse(
                    exceptionId: args.ExceptionId,
                    breakMode: breakMode,
                    description: args.Description,
                    code: args.Code);
            }
            else
            {
                output.AppendLine(Invariant($"Ignoring exception '{args.ExceptionId}' due to configuration."));
            }

            return(true);
        }