@Override
    public synchronized void add(PrestoWarning warning)
    {
        requireNonNull(warning, "warning is null");
        switch (warningHandlingLevel) {
            case SUPPRESS:
                break;
            case NORMAL:
                addWarningIfNumWarningsLessThanConfig(warning);
                break;
            case AS_ERROR:
                /* Parser warnings must be handled differently since we should not throw an exception when parsing.
                 * Warnings are collected and an exception with all warnings is thrown in {@link QueryPreparer#prepareQuery}
                 */
                if (warning.getWarningCode() == PARSER_WARNING.toWarningCode()) {
                    addWarningIfNumWarningsLessThanConfig(warning);
                }
                else {
                    throw new PrestoException(WARNING_AS_ERROR, warning.toString());
                }
        }
    }
@Test(expectedExceptions = {PrestoException.class})
    public void testWarningAsErrorThrowsException()
    {
        WarningCollector warningCollector = new DefaultWarningCollector(new WarningCollectorConfig(), WarningHandlingLevel.AS_ERROR);
        warningCollector.add(new PrestoWarning(new WarningCode(1, "1"), "warning 1"));
    }