Skiasharp: Recommended way to do error handling

Created on 24 Dec 2018  路  2Comments  路  Source: mono/SkiaSharp

Currently evaluating image libraries to switch to from my current usage of GDI+ (System.Drawing.dll).

Being used to having .NET libraries throw exceptions upon failure, I got really confused to see that SkiaSharp does _not_ follow this .NET pattern.

Methods that can fail seem to return false only, like e.g. SKBitmap.ScalePixels.

In addition I found no way to get extended error messages, once a function fails and returns false.

I would have expected to have at least something similar to Marshal.GetLastWin32Error but again found nothing.

I strongly feel that SkiaSharp is not usable in any medium sized project because of the minimal error reporting. On the other hand, given SkiaSharps popularity, I really do hope, I miss some essential points.

My questions:

  1. Can I tell SkiaSharp to throw exceptions instead of C style error reporting (returning booleans)?
  2. If not, can I query SkiaSharp to give me more error details than just a boolean?
type-question

All 2 comments

There was some discussion in #1169 about changes, but this is going to be really, really hard:

  • we can't do breaking changes
  • a duplicate API is not really viable
  • starting with exceptions now will be very confusing/unexpected
  • runtime flags will have conflicts

With regards to the original question:

If not, can I query SkiaSharp to give me more error details than just a boolean?

Often there is no actual data coming from the native API, so this is hard. However, some APIs also have an overload that provides some "result" or "status" value.

Was this page helpful?
0 / 5 - 0 ratings