#Throwing Exception
1 messages · Page 1 of 1 (latest)
so I check hierarchy if statement is true then I throw exception
I check here, everything is fine so far,
I got error here I guess
my error saying:
User
Event handler exception for event SLASHCOMMAND_ERRORED thrown from System.Threading.Tasks.Task SlashCommandError(DSharpPlus.SlashCommands.SlashCommandsExtension, DSharpPlus.SlashCommands.EventArgs.SlashCommandErrorEventArgs) (defined in FIrstDiscordBotC_.Program)
DSharpPlus.Exceptions.BadRequestException: Bad request: 400
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at DSharpPlus.Net.DiscordApiClient.<CreateInteractionResponseAsync>d__174.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at FIrstDiscordBotC_.Configurations.GlobalExceptionHandler.<HierarchyError>d__5.MoveNext() in C:\Users\User\Desktop\DiscordBots\DiscordBotDSharpPlus\Configurations\GlobalExceptionHandler.cs:line 112
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at FIrstDiscordBotC_.Configurations.GlobalExceptionHandler.<HandleErrors>d__1.MoveNext() in C:\Users\User\Desktop\DiscordBots\DiscordBotDSharpPlus\Configurations\GlobalExceptionHandler.cs:line 63
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at FIrstDiscordBotC_.Program.<SlashCommandError>d__3.MoveNext() in C:\Users\User\Desktop\DiscordBots\DiscordBotDSharpPlus\Program.cs:line 80
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at DSharpPlus.AsyncEvents.AsyncEvent`2.<>c__DisplayClass7_0.<<InvokeAsync>b__0>d.MoveNext()
Sorry, but in HandleErrors method I also have PermissionError which when user deosnt have permission to do smth, this exception happened. And it works fine. So whats difference between this Creating Response
They both comes from Ban method
because your permission check happens before the DeferAsync call
I understand now, so if I throw exception before deferring there will no be any issue, But If I dont do this, what you suggest for solution in handle error methods?
i recommend either making the hierarchy a pre-execution check too or handling it without throwing an exception