Ruby Knowledge Point three: operator

Source: Internet
Author: User

1. Logical operators

(1) Condition 1 | | Condition 2

Condition 1 is false , only need to judge condition 2

(2) Conditions 1 && conditions 2

Condition 1 is true , the condition must be judged 2

2. Range operator

(1) x.. Y from X to Y, including y

(2) X...y the previous element from X to Y, excluding Y

3. How to Handle exception

(1)

Begin

Handling of exceptions may occur

Rescue

Handling when an exception occurs

End

Specify variable name after rescue to get exception object

Such as:

Begin

Handling of exceptions may occur

Rescue = variable referencing an exception object

Handling when an exception occurs

End

Variable names are not specified, and variables that are automatically assigned when an exception occurs are used with the default variable name

Variable Significance
$! The last exception that occurred (Exception object)
[Email protected] Location information for the last occurrence of the exception

(2) post-processing

Begin

Handling of exceptions may occur

Rescue = variable referencing an exception object

Handling when an exception occurs

Ensure

Processing that you want to perform regardless of whether an exception occurred

End

4. Rescue modifier

Expression 1-Rescue expression 2

An exception occurs in Expression 1, and the value of expression 2 becomes the value of the overall expression.

Equivalent notation:

Begin

Expression 1

Rescue

Expression 2

End

Ruby Knowledge Point three: operator

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.