title: Exception not being caught in mulesoft
body: <p>I am working on an app and in case any exception occurs it prints the exception message appropriately.Here is my custom filter</p>
  
  <pre><code>    package filter;
  import java.io.IOException;
  import java.util.Map;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import org.mule.api.MuleMessage;
  public class ExceptionClass implements org.mule.api.routing.filter.Filter {
  
      @Override
      public boolean accept(MuleMessage message) {
          Map&lt;String,Object&gt; payload=(Map&lt;String,Object&gt;)message.getPayload();
  
          if(!payload.containsKey("productid"))
          {
  
              throw new java.lang.NullPointerException("no data found in payload "+payload.toString());
  
          }
          if(Integer.parseInt((String) payload.get("productid"))&lt;5)
          {
          throw new IllegalArgumentException("invalid input to payload " +payload.toString());
  
          }
          return true;
      }
  
  }
  </code></pre>
  
  <p>Here is the configuration of app</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:spring="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
  http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
  http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
  http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd"&gt;
      &lt;http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/&gt;
      &lt;flow name="muleexceptionhandlingFlow"&gt;
          &lt;http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP" &gt;
              &lt;http:response-builder statusCode="#[flowVars['statuscode']]" reasonPhrase="#[flowVars['reason']]"/&gt;
          &lt;/http:listener&gt;
          &lt;json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/&gt;
          &lt;custom-filter doc:name="Custom" class="filter.ExceptionClass"/&gt;
          &lt;logger message="payload:#[payload]" level="INFO" doc:name="Logger"/&gt;
          &lt;logger message="#[message]" level="INFO" doc:name="Logger"/&gt;
          &lt;set-payload value="payload:#[payload]" doc:name="Set Payload"/&gt;
      &lt;/flow&gt;
      &lt;choice-exception-strategy name="muleexceptionhandlingChoice_Exception_Strategy"&gt;
          &lt;catch-exception-strategy doc:name="Catch Missing Data Exception Strategy" logException="false" when="#[exception.causedBy(java.lang.NullPointerException)]"&gt;
              &lt;set-payload value="Missing data:#[payload]" doc:name="Set Payload"/&gt;
              &lt;set-variable variableName="reason" value="missing input data" doc:name="Variable"/&gt;
              &lt;set-variable variableName="statuscode" value="400" doc:name="Variable"/&gt;
          &lt;/catch-exception-strategy&gt;
          &lt;catch-exception-strategy doc:name="Catch Invalid data Exception Strategy" logException="false" when="#[exception.causedBy(java.lang.IllegalArgumentException)}"&gt;
              &lt;set-payload value="Invalid Data:#[payload]" doc:name="Set Payload"/&gt;
              &lt;set-variable variableName="reason" value="invalid input" doc:name="Variable"/&gt;
              &lt;set-variable variableName="statuscode" value="400" doc:name="Variable"/&gt;
          &lt;/catch-exception-strategy&gt;
      &lt;/choice-exception-strategy&gt;
  &lt;/mule&gt;
  </code></pre>
  
  <p>and here is the error message in case of nullpointer exception</p>
  
  <blockquote>
    <p>ERROR 2017-07-25 17:35:49,595
    [[muleexceptionhandling].HTTP_Listener_Configuration.worker.01]
    org.mule.exception.DefaultMessagingExceptionStrategy: 
    ******************************************************************************** Message               : no data found in payload {price=1000,
    productname=Shampoo} (java.lang.NullPointerException). Payload<br>
    : {price=1000, productname=Shampoo} Payload Type          :
    java.util.HashMap Filter                :
    filter.ExceptionClass@584d4f19 Element               :
    /muleexceptionhandlingFlow/processors/1 @
    muleexceptionhandling:null:null
    -------------------------------------------------------------------------------- Root Exception stack trace: java.lang.NullPointerException: no data
    found in payload {price=1000, productname=Shampoo}    at
    filter.ExceptionClass.accept(ExceptionClass.java:23)  at
    org.mule.routing.MessageFilter.accept(MessageFilter.java:93)  at
    org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMe
    ..................................</p>
  </blockquote>
  
  <p>Why is the exception not getting caught by exception handler</p>
  
  <p>Please guide!</p>