I have a piece of code:
            try {
                it.write()
            } catch (e : ErrnoException) {
                Logger.d("Playlist ${location.parentFile} could not be saved:", e)
            } catch (e: Exception) {
                Logger.d("Playlist ${location.parentFile} could not be saved:", e)
            } catch (e: Error) {
                Logger.d("Playlist ${location.parentFile} could not be saved:", e)
            } finally {
                try {
                    it.close()
                } catch (ex: Exception) {
                }
                isSaveNeeded = false
            }
It seems like everything possible should be caught. Yet my app crashes with:
Fatal Exception: java.io.FileNotFoundException: /storage/emulated/0/xenoamp/SCRATCH.m3u8: open failed: EACCES (Permission denied)
       at libcore.io.IoBridge.open(IoBridge.java:452)
       at java.io.FileOutputStream.(FileOutputStream.java:87)
       at java.io.FileOutputStream.(FileOutputStream.java:72)
       at pl.qus.io.XenoFileOutputStream.(SourceFile:36)
       at pl.qus.xenoamp.structures.PlaylistFiled.save(SourceFile:486)
       at pl.qus.xenoamp.xenoservice.XenoAmpService$onEventBackgroundThread$1.run(SourceFile:1304)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:224)
       at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by android.system.ErrnoException: open failed: EACCES (Permission denied)
       at libcore.io.Posix.open(Posix.java)
       at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
       at libcore.io.IoBridge.open(IoBridge.java:438)
       at java.io.FileOutputStream.(FileOutputStream.java:87)
       at java.io.FileOutputStream.(FileOutputStream.java:72)
       at pl.qus.io.XenoFileOutputStream.(SourceFile:36)
       at pl.qus.xenoamp.structures.PlaylistFiled.save(SourceFile:486)
       at pl.qus.xenoamp.xenoservice.XenoAmpService$onEventBackgroundThread$1.run(SourceFile:1304)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:224)
       at android.os.HandlerThread.run(HandlerThread.java:61)
It started do happen all of the sudden (probably afer another update to Android ibraries). Any idea how to catch this exception? My app has all the required read/write permissions in manifest + requests them at runtime for >KitKat.
The error occurs on Android 4, 5 and 6.
