Advertisement
happy-barney

catch example - java 01 - proposal

Jun 23rd, 2020
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 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.  
  7.         catch (IllegalStateException  e) { fireFailEvent(FailType.NETWORK_DENIED, null); }
  8.         catch (TaskCancelledException e) { throw e; }
  9.         catch (IOException            e) { L.e(e); fireFailEvent(FailType.IO_ERROR, e); }
  10.         catch (OutOfMemoryError       e) { L.e(e); fireFailEvent(FailType.OUT_OF_MEMORY, e); }
  11.         catch (Throwable              e) { L.e(e); fireFailEvent(FailType.UNKNOWN, e); }
  12.  
  13.         File imageFile = configuration.diskCache.get(uri);
  14.         if (imageFile != null && imageFile.exists() && imageFile.length() > 0) {
  15.             L.d(LOG_LOAD_IMAGE_FROM_DISK_CACHE, memoryCacheKey);
  16.             loadedFrom = LoadedFrom.DISC_CACHE;
  17.  
  18.             checkTaskNotActual();
  19.             bitmap = decodeImage(Scheme.FILE.wrap(imageFile.getAbsolutePath()));
  20.         }
  21.         if (bitmap == null || bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) {
  22.             L.d(LOG_LOAD_IMAGE_FROM_NETWORK, memoryCacheKey);
  23.             loadedFrom = LoadedFrom.NETWORK;
  24.  
  25.             String imageUriForDecoding = uri;
  26.             if (options.isCacheOnDisk() && tryCacheImageOnDisk()) {
  27.                 imageFile = configuration.diskCache.get(uri);
  28.                 if (imageFile != null) {
  29.                     imageUriForDecoding = Scheme.FILE.wrap(imageFile.getAbsolutePath());
  30.                 }
  31.             }
  32.  
  33.             checkTaskNotActual();
  34.             bitmap = decodeImage(imageUriForDecoding);
  35.  
  36.             if (bitmap == null || bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) {
  37.                 fireFailEvent(FailType.DECODING_ERROR, null);
  38.             }
  39.         }
  40.         return bitmap;
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement