Error Functions

Hi, I have created a table of functions to make errors very efficiently

local Errors = {
	
	Number = function(Value) -- Original
		error("number expected, got " .. typeof(Value))
	end,
	String = function(Value) -- Original
		error("string expected, got " .. typeof(Value))
	end,
	Boolean = function(Value) -- Original
		error("boolean expected, got " .. typeof(Value))
	end,
	
	CustomError = function(Value,Expected) -- Made by flkfv
		
		if typeof(Expected) == Value then
			return true
		end

		return false, error(typeof(Value) .. ' expected, got ' .. typeof(Expected))
		
	end,

}
1 Like

You can maybe improve it.

local function func(value, expected)
    if typeof(expected) == value then
        return true
    end
 
    return false, error(value .. ' expected, got ' .. typeof(expected))
end

local successful = func('boolean', 1) --> boolean expected, got number
print(successful) --> false
1 Like

Can I put your code in mine? please?

Sure, feel free to use. I wrote this on mobile so may not work exactly.

calm any error I solve and thanks