This will take a RecognitionException, and create a sensible error
message out of it
969095
private List<String> createErrorMessage( RecognitionException e ) {
        List<String> codeAndMessage = new ArrayList<String>( 2 );
        String message;
        if ( e instanceof MismatchedTokenException ) {
            MismatchedTokenException mte = (MismatchedTokenException) e;
            String expecting = mte instanceof DroolsMismatchedTokenException ? ((DroolsMismatchedTokenException)mte).getTokenText() : getBetterToken( mte.expecting );
            if ( tokenNames != null && mte.expecting >= 0 && mte.expecting < tokenNames.length ) {
                message = String
                        .format(
                                 MISMATCHED_TOKEN_MESSAGE_COMPLETE,
                                 e.line,
                                 e.charPositionInLine,
                                 getBetterToken( e.token ),
                                 expecting,
                                 formatParserLocation() );
                codeAndMessage.add( message );
                codeAndMessage.add( "ERR 102" );
            } else {
                message = String
                        .format(
                                 MISMATCHED_TOKEN_MESSAGE_PART,
                                 e.line,
                                 e.charPositionInLine,
                                 getBetterToken( e.token ),
                                 formatParserLocation() );
                codeAndMessage.add( message );
                codeAndMessage.add( "ERR 102" );
            }
        } else if ( e instanceof MismatchedTreeNodeException ) {
            MismatchedTreeNodeException mtne = (MismatchedTreeNodeException) e;
            if ( mtne.expecting >= 0 && mtne.expecting < tokenNames.length ) {
                message = String
                        .format(
                                 MISMATCHED_TREE_NODE_MESSAGE_COMPLETE,
                                 e.line,
                                 e.charPositionInLine,
                                 getBetterToken( e.token ),
                                 getBetterToken( mtne.expecting ),
                                 formatParserLocation() );
                codeAndMessage.add( message );
                codeAndMessage.add( "ERR 106" );
            } else {
                message = String
                        .format(
                                 MISMATCHED_TREE_NODE_MESSAGE_PART,
                                 e.line,
                                 e.charPositionInLine,
                                 getBetterToken( e.token ),
                                 formatParserLocation() );
                codeAndMessage.add( message );
                codeAndMessage.add( "ERR 106" );
            }
        } else if ( e instanceof NoViableAltException ) {
            // NoViableAltException nvae = (NoViableAltException) e;
            message = String.format(
                                     NO_VIABLE_ALT_MESSAGE,
                                     e.line,
                                     e.charPositionInLine,
                                     getBetterToken( e.token ),
                                     formatParserLocation() );
            codeAndMessage.add( message );
            codeAndMessage.add( "ERR 101" );
        } else if ( e instanceof EarlyExitException ) {
            // EarlyExitException eee = (EarlyExitException) e;
            message = String.format(
                                     EARLY_EXIT_MESSAGE,
                                     e.line,
                                     e.charPositionInLine,
                                     getBetterToken( e.token ),
                                     formatParserLocation() );
            codeAndMessage.add( message );
            codeAndMessage.add( "ERR 105" );
        } else if ( e instanceof MismatchedSetException ) {
            MismatchedSetException mse = (MismatchedSetException) e;
            String expected = expectedTokensAsString( mse.expecting );
            message = String.format(
                                     MISMATCHED_SET_MESSAGE,
                                     e.line,
                                     e.charPositionInLine,
                                     getBetterToken( e.token ),
                                     expected,
                                     formatParserLocation() );
            codeAndMessage.add( message );
            codeAndMessage.add( "ERR 107" );
        } else if ( e instanceof DroolsMismatchedSetException ) {
            DroolsMismatchedSetException mse = (DroolsMismatchedSetException) e;
            String expected = Arrays.asList( mse.getTokenText() ).toString();
            message = String.format(
                                     MISMATCHED_SET_MESSAGE,
                                     e.line,
                                     e.charPositionInLine,
                                     getBetterToken( e.token ),
                                     expected,
                                     formatParserLocation() );
            codeAndMessage.add( message );
            codeAndMessage.add( "ERR 107" );
        } else if ( e instanceof MismatchedNotSetException ) {
            MismatchedNotSetException mse = (MismatchedNotSetException) e;
            String expected = expectedTokensAsString( mse.expecting );
            message = String.format(
                                     MISMATCHED_NOT_SET_MESSAGE,
                                     e.line,
                                     e.charPositionInLine,
                                     getBetterToken( e.token ),
                                     expected,
                                     formatParserLocation() );
            codeAndMessage.add( message );
            codeAndMessage.add( "ERR 108" );
        } else if ( e instanceof FailedPredicateException ) {
            FailedPredicateException fpe = (FailedPredicateException) e;
            message = String.format(
                                     FAILED_PREDICATE_MESSAGE,
                                     e.line,
                                     e.charPositionInLine,
                                     fpe.ruleName,
                                     fpe.predicateText,
                                     formatParserLocation() );
            codeAndMessage.add( message );
            codeAndMessage.add( "ERR 103" );
        }
        if ( codeAndMessage.get( 0 ).length() == 0 ) {
            codeAndMessage.add( "?????" );
        }
        return codeAndMessage;
    }
513589
def exception_to_signal(sig: Union[SignalException, signal.Signals]):
    
    if isinstance(sig, SignalException):
        signum = sig.signum
    else:
        signum = sig.value
    signal.signal(signum, signal.SIG_DFL)
141781
@Override
  protected void handleError(Suppressible s, Throwable t) {
    if (t instanceof ErrorProneError) {
      throw (ErrorProneError) t;
    }
    if (t instanceof CompletionFailure) {
      throw (CompletionFailure) t;
    }
    TreePath path = getCurrentPath();
    throw new ErrorProneError(
        s.canonicalName(),
        t,
        (DiagnosticPosition) path.getLeaf(),
        path.getCompilationUnit().getSourceFile());
  }
212399
def handle_namespace_invalid(self, line: str, position: int, tokens: ParseResults) -> None:
        """"""
        name = tokens[NAME]
        raise NakedNameWarning(self.get_line_number(), line, position, name)
1195380
def parse_error(self, exception=ParseError, *args):
        
        return self._src.parse_error(exception, *args)
766881
function lexError(message, input, index) {
	let lexMessage = message + "\n\n";

	// Show input characters surrounding the source of the error.
	for (
		let i = Math.max(0, index - 16);
		i < Math.min(index + 16, input.length);
		i++
	) {
		lexMessage += input[i];
	}

	error(lexMessage);
}
561031
def format_error(e):
    

    if isinstance(e, PyMacaronException):
        return e.to_model()

    if isinstance(e, PyMacaronCoreException) and e.__class__.__name__ == 'ValidationError':
        return ValidationError(str(e)).to_model()

    # Turn this exception into a PyMacaron Error model
    return UnhandledServerError(str(e)).to_model()
614179
def _fail(self, message, text, i):
        """"""

        raise ValueError("{}:\n{}".format(message, text[i : i + 79]))
1288641
def error(message)
      puts message.prepend('✗ ').colorize(:light_red)
    end
800738
protected ImageDescriptor handleImageDescriptorError(Object[] params, Throwable exception) {
		if (exception instanceof NullPointerException) {
			final Object defaultImage = getDefaultImage();
			if (defaultImage instanceof ImageDescriptor) {
				return (ImageDescriptor) defaultImage;
			}
			if (defaultImage instanceof Image) {
				return ImageDescriptor.createFromImage((Image) defaultImage);
			}
			return super.imageDescriptor(params[0]);
		}
		return Exceptions.throwUncheckedException(exception);
	}
1136554
function Exception(message, innerException) {
  if (!message) {
    throw new Exception("Argument 'message' is required but was '" +
      (message === null ? "null" : "undefined") + "'");
  }
  if (typeof message !== 'string') {
    throw new Exception("Argument 'message' must be of type 'string' but was '" + typeof message + "'");
  }

  if (innerException === undefined && typeof message !== 'string') {
    innerException = message;
    message = innerException.message || innerException.toString();
  }

  this.message = message;
  this.innerException = innerException;
  this.toString = function () {
    return message;
  };
}
275269
function throwError(token, messageFormat) {
        var error,
            args = Array.prototype.slice.call(arguments, 2),
            msg = messageFormat.replace(
                /%(\d)/g,
                function (whole, index) {
                    assert(index < args.length, 'Message reference must be in range');
                    return args[index];
                }
            );

        error = new Error(msg);
        error.index = index;
        error.description = msg;
        throw error;
    }
1079327
def raise_invalid_type_exception(self):
        """"""
        message = 'Expecting element type of %s' % (
            self._parameter.element_type.__name__)
        err = ValueError(message)
        return err
442825
function error(msg){
  utils.assertType(msg, 'string', 'msg');
  var err = new Error(msg.val);
  err.fromStylus = true;
  throw err;
}
1307194
def parse_error(
        self, exception=ParseError, *args
    ):  # type: (ParseError.__class__, ...) -> ParseError
        
        line, col = self._to_linecol()

        return exception(line, col, *args)
944908
def _init_message(self):
        """"""
        try:
            self.message = compat.text_type(self.error)
        except UnicodeError:
            try:
                self.message = str(self.error)
            except UnicodeEncodeError:
                # Fallback to args as neither unicode nor
                # str(Exception(u'\xe6')) work in Python < 2.6
                self.message = self.error.args[0]
        if not isinstance(self.message, compat.text_type):
            self.message = compat.text_type(self.message, 'ascii', 'replace')
170508
def _ReraiseTypeErrorWithFieldName(message_name, field_name):
  """"""
  exc = sys.exc_info()[1]
  if len(exc.args) == 1 and type(exc) is TypeError:
    # simple TypeError; add field name to exception message
    exc = TypeError('%s for field %s.%s' % (str(exc), message_name, field_name))

  # re-raise possibly-amended exception with original traceback:
  six.reraise(type(exc), exc, sys.exc_info()[2])