Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
enum {
    E_OK,
    E_OUT_OF_RANGE
};
int square(int x, int *result) {
    if (x > 1073741823) {
        return E_OUT_OF_RANGE;
    }
    *result = x*x;
    return E_OK;
}
		
		
	throw domain_error("oops!");
		
		
	throw new ArgumentException(nameof(×));
		
		
	void foo(int x)
in
{
    assert(x != 0, "wrong value for x");
}
body
{
    // function
}
		
		
	error(badarg).
		
		
	  if (x > largest_value) error stop "Illegal value in function."
		
		
	return nil, fmt.Errorf("invalid value for x: %v", x)
		
		
	throw new IllegalArgumentException("Invalid value for x: $x")
		
		
	sqrt' :: Int -> Either String Int
sqrt' x | x < 0 = Left "Invalid argument"
sqrt' x         = Right (sqrt x)
		
		
	throw new Error('x is invalid');
		
		
	<T> void f(T x) {
    Objects.requireNonNull(x);
}
		
		
	<T> void f(T x) throws Exception {
    if (x != value) throw new Exception();
}
		
		
	void f(int x) {
    Objects.checkIndex(x, 123);
}
		
		
	throw new IllegalArgumentException("Invalid value for x:" + x);
		
		
	return nil, "Invalid argument x"
		
		
	error("Invalid argument x")
		
		
	throw new \InvalidArgumentException($x . ' is invalid.');
		
		
	die "Invalid argument $x";
		
		
	raise ValueError("x is invalid")
		
		
	def check_index(length):
    def wrapper(function):
        def wrapped(arg):
            error(arg >= length)
            return function(arg)
        return wrapped
    return wrapper
def require_nonnull(function):
    def wrapped(arg):
        error(arg is None)
        return function(arg)
    return wrapped
def error(value):
    if value:
        raise ValueError
@require_nonnull
@check_index(123)
def function(value):
    ...
function(x)
		
		
	def check_range(start, stop):
    def check(value):
        if not start <= value < stop:
            raise ValueError
        return True
    def wrapper(f):
        def wrapped(*args, **kwargs):
            values = *args, *kwargs.values()
            if all(map(check, values)):
                return f(*args, **kwargs)
        return wrapped
    return wrapper
@check_range(0, 3.14159)
def function(*args, **kwargs):
    ...
function(x)
		
		
	raise ArgumentError, "invalid value #{x}."
		
		
	enum CustomError { InvalidAnswer }
fn do_stuff(x: i32) -> Result<i32, CustomError> {
    if x != 42 {
        Err(CustomError::InvalidAnswer)
    } else {
        Ok(x)
    }
}