> For the complete documentation index, see [llms.txt](https://neiizun.gitbook.io/lightdrop/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://neiizun.gitbook.io/lightdrop/usage/exception-handling.md).

# Exception handling

ExceptionHandler are a way to prevent exception from throwing in a command method.&#x20;

```java
public class MyCommand {
    @Command(name = "mycommand")
    public void myCommand(CommandContext context) {
        throw new IllegalArgumentException();
    }

    @ExceptionHandler(commands = {"mycommand"}, exception = IllegalArgumentException.class)
    public void except(Exception e, CommandContext context) {
        context.getChannel().sendMessage("An exception has occured").complete();
    }
}
```

You must specify the commands to handle, but if you want handle all commands you can put "\*". Handled exception is not required, default Exception.class.

Not that if ExceptionHandler is not used, no exception will be thrown to the console.
