Files
flipper/docs/extending/error-handling.mdx
Kevin Strider 669bc74acd error-handling.mdx (Creating Plugins - Error Handling)
Summary: Restyle of page, including changes to spelling, grammar, links, and structure (where relevant).

Reviewed By: aigoncharov

Differential Revision: D36626777

fbshipit-source-id: 65c5fcac860ff47c775fc43c053a8a55eb4804e9
2022-05-25 03:11:36 -07:00

40 lines
2.1 KiB
Plaintext

---
id: error-handling
title: Error Handling
---
Errors in Flipper plugins should be hidden from the user while providing actionable data to the plugin Developer.
## Android
To gracefully handle errors in Flipper, use the following classes:
* `FlipperResponder` - an instance is provided to the client plugin on every method call, which enables it to return results. When an error occurs during a Flipper method call that can't be handled, pass the error to the responder. This will let the desktop plugin handle it, and if it doesn't, the error will be displayed in the DevTools console.
* `ErrorReportingRunnable` - a custom `Runnable` that catches all exceptions, stopping them from crashing the application and reports them to Flipper. These error messages will show up in the DevTools console.
Executing the following block of code will always finish without error but may transfer any silent errors to the Flipper desktop app:
```java
new ErrorReportingRunnable(mConnection) {
@Override
public void runOrThrow() throws Exception {
mightThrowException();
}
}.run();
```
During plugin development these java stack traces are surfaced in the chrome dev console.
Always use `ErrorReportingRunnable` for error handling instead of `try`/`catch` or, even worse, letting errors crash the app. With ErrorReportingRunnable you won't block anyone, and you won't hide any stack traces.
## C++
To gracefully handle errors in Flipper, all transactions are performed inside of a 'Try' block, which catches all exceptions, stops them from crashing the application, and reports them to the plugin Developer. This includes your own customs implementations of `FlipperPlugin::didConnect()` and `FlipperConnection::send()` and `::receive()`.
This means you can safely throw exceptions in your plugin code; the exception messages will be sent to the Flipper desktop app.
During plugin development the exception messages are surfaced in the Chrome dev console.
If your plugin performs asynchronous work in which exceptions are thrown, these exceptions will not be caught by the Flipper infrastructure. You should handle them appropriately.