AndreKR
AndreKR

Reputation: 33697

What is the part after "catch" called?

What do we call the code highlighted in yellow?

example

in code it would be:

try{
    ...
} catch (Exception $e) { // the part within the brakets
    ...
}

I was thinking "catch expression" maybe, but I don't think I have ever read that anywhere.

Upvotes: 2

Views: 184

Answers (2)

leonardkraemer
leonardkraemer

Reputation: 6813

The expression you ask about is the catch clause which, in Java and many other languages, consists of the CatchType and Identifier and Block

CatchClause:  
    catch ( {VariableModifier} CatchType Identifier ) Block

in Java, C# and C++ the CatchType and Identifier part is typically called

catch parameter

It might be called differently in other languages, but I think catch parameter is very descriptive.

Sometimes it is also called the

error object

or, or

exception variable

Upvotes: 3

I_Al-thamary
I_Al-thamary

Reputation: 4043

The name of all parts is A catch block or catch statement and the yellow part called ReferenceError , Exception Handler or the error object .

"Try" and "catch" are keywords that represent the handling of exceptions due to data or coding errors during program execution. A try block is the block of code in which exceptions occur. A catch block catches and handles try block exceptions.

The try/catch statement is used in many programming languages, including C programming language (C++ and C#), Java, JavaScript and Structured Query Language (SQL).

Try defines a block of statements that may throw an exception. When a specific type of exception occurs, a catch block catches the exception. If an exception is not handled by try/catch blocks, the exception escalates through the call stack until the exception is caught or an error message is printed by the compiler.

A try/catch block also may be nested with one or more try/catch statements. Each try statement has a matching catch statement to handle the exception. If an exception's inner try statement does not have a matching catch statement, subsequent try statement catch handlers are checked. This process continues until all inner try statements are checked for a matching catch statement. If a catch statement does not match, the runtime system handles the exception.

Try/catch block examples include:

  1. A try block followed by a catch block
  2. A try block followed by one or more catch blocks
  3. A try block followed by another try block and then followed by a corresponding catch block

catch When an error occurs, programming language generates an object containing the details about it. The object is then passed as an argument to catch:

For all built-in errors, the error object inside catch block has two main properties:

name Error name. For an undefined variable that’s "ReferenceError". message Textual message about error details. There are other non-standard properties available in most environments. One of most widely used and supported is:

stack Current call stack: a string with information about the sequence of nested calls that led to the error. Used for debugging purposes.

Sources: https://www.techopedia.com/definition/25641/trycatch-block

https://javascript.info/try-catch

https://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html

https://learn.microsoft.com/en-us/dotnet/standard/exceptions/how-to-use-the-try-catch-block-to-catch-exceptions

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch

Upvotes: 1

Related Questions