Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
Javascript error handling with throw and catch block

I have the below async function that throws an error if I am not running in test mode in the else block. If it is test mode, it executes a bunch of log statements in the execute function, and then jumps to createMyTestSuite where bad things may happen which I catch in the catch block. My question is, do I need to throw again from catch? I know the first throw will jump execution to the catch block.

  public static async load(testMode:Mode): Promise<void> {
    try {
      if (testMode) {
        execute();
      } else {
        throw new Error('Can only run test mode in load');
      }
      await this.createMyTestSuite();
    } catch(error) {
      dLogger?.error('failed to load create my test suite ', {error});
      throw error;
    }
  }
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can return a rejected promise from the catch block.

public static async load(testMode:Mode): Promise<void> {
  try {
    if (testMode) {
      execute();
    } else {
      throw new Error('Can only run test mode in load');
    }
    await this.createMyTestSuite();
  } catch(error) {
    dLogger?.error('failed to load create my test suite ', {error});
    return Promise.reject(error);
  } 
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda