Advertisement
happy-barney

catch example - java 01 - source

Jun 23rd, 2020
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. // Example borrowed from https://github.com/nostra13/Android-Universal-Image-Loader
  2. // File: library/src/main/java/com/nostra13/universalimageloader/core/LoadAndDisplayImageTask.java
  3.  
  4.     private Bitmap tryLoadBitmap() throws TaskCancelledException {
  5.         Bitmap bitmap = null;
  6.         try {
  7.             File imageFile = configuration.diskCache.get(uri);
  8.             if (imageFile != null && imageFile.exists() && imageFile.length() > 0) {
  9.                 L.d(LOG_LOAD_IMAGE_FROM_DISK_CACHE, memoryCacheKey);
  10.                 loadedFrom = LoadedFrom.DISC_CACHE;
  11.  
  12.                 checkTaskNotActual();
  13.                 bitmap = decodeImage(Scheme.FILE.wrap(imageFile.getAbsolutePath()));
  14.             }
  15.             if (bitmap == null || bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) {
  16.                 L.d(LOG_LOAD_IMAGE_FROM_NETWORK, memoryCacheKey);
  17.                 loadedFrom = LoadedFrom.NETWORK;
  18.  
  19.                 String imageUriForDecoding = uri;
  20.                 if (options.isCacheOnDisk() && tryCacheImageOnDisk()) {
  21.                     imageFile = configuration.diskCache.get(uri);
  22.                     if (imageFile != null) {
  23.                         imageUriForDecoding = Scheme.FILE.wrap(imageFile.getAbsolutePath());
  24.                     }
  25.                 }
  26.  
  27.                 checkTaskNotActual();
  28.                 bitmap = decodeImage(imageUriForDecoding);
  29.  
  30.                 if (bitmap == null || bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) {
  31.                     fireFailEvent(FailType.DECODING_ERROR, null);
  32.                 }
  33.             }
  34.         } catch (IllegalStateException e) {
  35.             fireFailEvent(FailType.NETWORK_DENIED, null);
  36.         } catch (TaskCancelledException e) {
  37.             throw e;
  38.         } catch (IOException e) {
  39.             L.e(e);
  40.             fireFailEvent(FailType.IO_ERROR, e);
  41.         } catch (OutOfMemoryError e) {
  42.             L.e(e);
  43.             fireFailEvent(FailType.OUT_OF_MEMORY, e);
  44.         } catch (Throwable e) {
  45.             L.e(e);
  46.             fireFailEvent(FailType.UNKNOWN, e);
  47.         }
  48.         return bitmap;
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement