title: Is it ok to wrap potential OutOfMemory error with try/catch?
body: <p>I'm trying to Change images formats, by using Bitmap compression, but decoding some images is generating OOM, so i came up with this:</p>
  
  <pre><code>    fun compressImage(filePath: String, sampleRate: Int? = null): Bitmap {
          val options = BitmapFactory.Options().apply {
              inJustDecodeBounds = true
          }
          BitmapFactory.decodeFile(filePath, options)
  
          val reqSampleRate = sampleRate ?: calculateInSampleSize(options, maxWidth, maxHeight)
  
          try {
              options.inSampleSize = reqSampleRate
              options.inPreferredConfig = Bitmap.Config.ARGB_8888
              options.inJustDecodeBounds = false
              return BitmapFactory.decodeFile(filePath, options)
          } catch (e: OutOfMemoryError) {
              System.gc()
              // increase sample rate to get smaller bitmap size
              return compressImage(filePath, reqSampleRate + 2)
          }
      }
  </code></pre>
  
  <p>Is it a good practice to wrap potential OOM with try/catch? or is there any other solution?</p>