Reputation: 33697
What do we call the code highlighted in yellow?
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
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
exception variable
Upvotes: 3
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:
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://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
Upvotes: 1