Created
April 27, 2022 12:57
-
-
Save luizpicolo/cad5da3bb233a34c9c7759423ab2da53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ErroCustomizado extends Error { | |
constructor(titulo, mensagem){ | |
super(mensagem); | |
this.name = titulo | |
} | |
get mensagem(){ | |
return this.name + ': ' + this.message + "\nLinha do erro: " + this.stack.split("\n")[1].split(":")[1] | |
} | |
} | |
class Retangulo { | |
constructor(largura, altura){ | |
this.largura = largura; | |
this.altura = altura; | |
} | |
area(){ | |
try { | |
return this.calcular(this.largura, this.altura); | |
} catch (error){ | |
return error.stack | |
} | |
} | |
calcular(largura, altura){ | |
if (altura > 0 && largura > 0){ | |
return this.altura * this.largura; | |
} else { | |
//return "teste" | |
throw new ErroCustomizado("Erro método Calcular", "Largura e Altura não podem ser menores ou iguais a zero"); | |
} | |
} | |
} | |
var retangulo = new Retangulo(0, 0) | |
console.log(retangulo.area()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment