title: Malformed PDF print doesn't catch RuntimeException
body: <p>I try to print a PDF file and it works fine until I try to print a malformed PDF file.
  I don't know why the application crashes even though I used <code>try / catch</code> to prevent crashes. I checked and found out that <code>PrintManager.java:1101</code> throws <code>RuntimeException</code>:</p>
  
  <pre><code> case MSG_ON_KILL: {
       if (DEBUG) {
           Log.i(LOG_TAG, "onKill()");
       }
  
       String reason = (String) message.obj;
       throw new RuntimeException(reason);
   }
  </code></pre>
  
  <p>so code below shouldn't lead to crash: </p>
  
  <pre><code>public static void startPdfPrintProcedure(@NonNull Context context, @NonNull String filePath, @Nullable String jobName) {
      try {
          PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
          String jobName = formatDefaultJobName(context.getResources(), jobName);
          PrintDocumentAdapter pda = new SimplePrintDocumentAdapter(new File(filePath));
          if (printManager != null) {
              try {
                  printManager.print(jobName, pda, null); // &lt;- crash here even though there is a try/catch
              } catch (RuntimeException e) {
                  showUnknownError();
              }
          } else {
              showUnknownError();
          }
      } catch (RuntimeException e) {
          showUnknownError();
      }
  }
  </code></pre>
  
  <p>Exception that I get after try to print PDF. : </p>
  
  <pre><code> java.lang.RuntimeException: Cannot print a malformed PDF file
      at android.print.PrintManager$PrintDocumentAdapterDelegate$MyHandler.handleMessage(PrintManager.java:1101)
      at android.os.Handler.dispatchMessage(Handler.java:112)
      at android.os.Looper.loop(Looper.java:216)
      at android.app.ActivityThread.main(ActivityThread.java:7625)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
  </code></pre>
  
  <p>Why <code>try/catch</code> code doesn't catch this exception? How can I secure this piece of code from crashing?</p>