In my app I have an image resizing method that I use to create a thumbnail of an image; here is the code.
private func resize(withSize size: CGSize) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 1)
defer { UIGraphicsEndImageContext() }
draw(in: CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height))
return UIGraphicsGetImageFromCurrentImageContext()
}
When resizing big images (can be a 7Mb PNG that uncompressed became 200Mb...) the draw(in:) crash with following error: EXC_RESOURCE RESOURCE_TYPE_MEMORY.
This is not an exception that can be catched with a try-catch block.
How can I handle a controlled shutdown instead of a crash?