class IsNullException extends Error { }
class IsEmptyException extends Error { }
function throwWhenNullOrEmpty(array: any[]) {
if (array == null) {
throw new IsNullException
}
if (array.length === 0) {
throw new IsEmptyException
}
}
try {
throwWhenNullOrEmpty([])
}
catch (e) {
if (e instanceof IsEmptyException) {
console.log("array is empty")
} else {
console.log("array is not specified")
}
}