fix: converted single to triple backticks10 (#36237)

This commit is contained in:
Randell Dawson
2019-06-20 14:53:53 -07:00
committed by Tom
parent da6bd27eec
commit 039fea8b6d
75 changed files with 1880 additions and 1655 deletions

View File

@@ -8,62 +8,66 @@ localeTitle: خطأ في التعامل ومحاولة رمي الصيد
#### `try...catch`
`try {
throw new Error('my error');
}
catch (e) {
console.error(e.message);
}
// Output:
// my error
`
```javascript
try {
throw new Error('my error');
}
catch (e) {
console.error(e.message);
}
// Output:
// my error
```
#### `try...finally` :
`try {
throw new Error('my error');
}
finally {
console.error('finally');
}
// Output:
// finally
`
```javascript
try {
throw new Error('my error');
}
finally {
console.error('finally');
}
// Output:
// finally
```
_ملاحظة:_ عندما لا `catch` الخطأ ، فإنه في الواقع لا "يصطاد" ​​، حتى لو تم تنفيذ الحظر `finally` . وهذا يعني أن الخطأ سيستمر في كتلة `try` العليا (أو الكتلة الرئيسية).
#### `try...catch...finally` :
`try {
throw new Error('my error');
}
catch (e) {
console.error(e.message);
}
finally {
console.error('finally');
}
// Output:
// my error
// finally
`
```javascript
try {
throw new Error('my error');
}
catch (e) {
console.error(e.message);
}
finally {
console.error('finally');
}
// Output:
// my error
// finally
```
الاستخدام النموذجي:
`try {
openFile(file);
readFile(file)
}
catch (e) {
console.error(e.message);
}
finally {
closeFile(file);
}
`
```javascript
try {
openFile(file);
readFile(file)
}
catch (e) {
console.error(e.message);
}
finally {
closeFile(file);
}
```
#### `try...catch` متداخلة `try...catch`
@@ -72,75 +76,80 @@ _ملاحظة:_ عندما لا `catch` الخطأ ، فإنه في الواقع
* اعتبر عبارة `try-catch` داخل كتلة `try` .
* رمي الخطأ صعودا.
`try {
try {
throw new Error('my error');
}
catch (e) {
console.error('inner', e.message);
throw e;
}
finally {
console.log('finally');
}
}
catch (e) {
console.error('outer', e.message);
}
// Output:
// inner my error
// finally
// outer my error
`
```javascript
try {
try {
throw new Error('my error');
}
catch (e) {
console.error('inner', e.message);
throw e;
}
finally {
console.log('finally');
}
}
catch (e) {
console.error('outer', e.message);
}
// Output:
// inner my error
// finally
// outer my error
```
#### أنواع الخطأ
##### خطأ مرجعي
`var x;
try {
x = y + 1; // y cannot be referenced (used)
}
catch(err) {
console.log(err.name, err.message);
}
// ReferenceError y is not defined
`
```javascript
var x;
try {
x = y + 1; // y cannot be referenced (used)
}
catch(err) {
console.log(err.name, err.message);
}
// ReferenceError y is not defined
```
##### خطأ في بناء الجملة
`try {
eval("alert('Hello)"); // Missing ' will produce an error
}
catch(err) {
console.log(err.name,err.message);
}
// SyntaxError Invalid or unexpected token
`
```javascript
try {
eval("alert('Hello)"); // Missing ' will produce an error
}
catch(err) {
console.log(err.name,err.message);
}
// SyntaxError Invalid or unexpected token
```
##### خطأ مطبعي
`var num = 1;
try {
num.toUpperCase(); // You cannot convert a number to upper case
}
catch(err) {
console.log(err.name, err.message);
}
// TypeError num.toUpperCase is not a function
`
```javascript
var num = 1;
try {
num.toUpperCase(); // You cannot convert a number to upper case
}
catch(err) {
console.log(err.name, err.message);
}
// TypeError num.toUpperCase is not a function
```
##### خطأ URI
`try {
decodeURI("%%%"); // You cannot URI decode these percent signs
}
catch(err) {
console.log(err.name, err.message);
}
// URIError URI malformed
`
```javascript
try {
decodeURI("%%%"); // You cannot URI decode these percent signs
}
catch(err) {
console.log(err.name, err.message);
}
// URIError URI malformed
```
#### معلومات اكثر: