How error management works in FPDF
mainInstead of checking for errors after every single method call, go-pdf/fpdf uses an internal error state. If a method fails, an internal error field is set, and subsequent method calls typically return without performing operations.
To manage errors effectively:
- Check at the end: It is generally sufficient to check for errors after calling
Output()orOutputFileAndClose(). - Check status: Use
Ok()to check if the instance is in a valid state, orErr()to see if an error has occurred. - Retrieve error: Use
Error()to get the specific error message. - Manual error injection: If an error occurs in your own application logic during generation, you can transfer it to the FPDF instance using
SetError()orSetErrorf().