[JS] Try & Catch statements

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

Oblivion

Member
CC Dev Team
Jul 25, 2016
26
32
73
Try and Catch statement example.
You will need at least some knowledge of JavaScript if you want to use this example.

Example
Code:
try {
    //Try statement lets you test your code for errors
    console.log('Hello');
} catch (err) {
    //Catch statement "catches" any errors from your try statement and executes whatever you've placed as your error handling
    console.error('error occurred : ' + err);
}

Step by step guide
  • Create your try statement:
Code:
try {
  
}

  • Add your code inside the try statement:
Code:
try {
    console.log('Hello');
}

  • Add a catch statement to the end of your try statement and make a function called err
Code:
catch (err) {
    console.error('error occurred : ' + err);
}

  • Now run your code and if it catches any errors it will console.error() them.
 
  • Like
Reactions: Dana White
General chit-chat
Help Users
  • No one is chatting at the moment.
    @ QM|T_JinX: :weed: