                         resizeWidth: Int = 0, resizeHeight: Int = 0) throws -> Data {
         var config = config.rawValue
         if WebPValidateConfig(&config) == 0 {
-            fatalError("invalid config")
+            throw WebPEncoderError.invalidParameter
         }
 
         var picture = WebPPicture()
         if WebPPictureInit(&picture) == 0 {
-            fatalError("version error")
+            throw WebPEncoderError.invalidParameter
         }
 
         picture.use_argb = config.lossless == 0 ? 0 : 1

        let ok = importer(&picture, dataPtr, Int32(stride))
        if ok == 0 {
            WebPPictureFree(&picture)
            fatalError("can't import picture")
        }

        if resizeHeight > 0 && resizeHeight > 0 {
            if (WebPPictureRescale(&picture, Int32(resizeWidth), Int32(resizeHeight)) == 0) {
                fatalError("can't rescale picture")
            }
        }


        if WebPEncode(&config, &picture) == 0 {
            WebPPictureFree(&picture)

            let error = WebPEncodeStatusCode(rawValue:  Int(picture.error_code.rawValue))!
            throw error
        }
        WebPPictureFree(&picture)
