Esempio n. 1
0
  public Value execute(Env env) {
    try {
      return _block.execute(env);
    } catch (QuercusLanguageException e) {
      Value value = null;

      try {
        value = e.toValue(env);
      } catch (Throwable e1) {
        throw new QuercusRuntimeException(e1);
      }

      for (int i = 0; i < _catchList.size(); i++) {
        Catch item = _catchList.get(i);

        if (value != null && value.isA(item.getId()) || item.getId().equals("Exception")) {
          if (value != null) item.getExpr().evalAssignValue(env, value);
          else item.getExpr().evalAssignValue(env, NullValue.NULL);

          return item.getBlock().execute(env);
        }
      }

      throw e;

    } catch (QuercusDieException e) {
      for (int i = 0; i < _catchList.size(); i++) {
        Catch item = _catchList.get(i);

        if (item.getId().equals("QuercusDieException")) {
          item.getExpr().evalAssignValue(env, env.createException(e));

          return item.getBlock().execute(env);
        }
      }

      throw e;

    } catch (QuercusExitException e) {
      for (int i = 0; i < _catchList.size(); i++) {
        Catch item = _catchList.get(i);

        if (item.getId().equals("QuercusExitException")) {
          item.getExpr().evalAssignValue(env, env.createException(e));

          return item.getBlock().execute(env);
        }
      }

      throw e;

    } catch (Exception e) {
      for (int i = 0; i < _catchList.size(); i++) {
        Catch item = _catchList.get(i);

        if (item.getId().equals("Exception")) {
          Throwable cause = e;

          // if (e instanceof QuercusException && e.getCause() != null)
          // cause = e.getCause();

          item.getExpr().evalAssignValue(env, env.createException(cause));

          return item.getBlock().execute(env);
        }
      }

      if (e instanceof QuercusException) throw (QuercusException) e;
      else throw new QuercusException(e);
    }
  }