Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!