Throw errors instead of strings. (#1974)

Blocks and generators
This commit is contained in:
Neil Fraser
2018-07-16 16:33:44 -07:00
committed by GitHub
parent 99ebefa1bf
commit c8bfc888c8
23 changed files with 55 additions and 55 deletions

View File

@@ -183,7 +183,7 @@ Blockly.Python['lists_getIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_getIndex).';
throw Error('Unhandled combination (lists_getIndex).');
};
Blockly.Python['lists_setIndex'] = function(block) {
@@ -254,7 +254,7 @@ Blockly.Python['lists_setIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_setIndex).';
throw Error('Unhandled combination (lists_setIndex).');
};
Blockly.Python['lists_getSublist'] = function(block) {
@@ -277,7 +277,7 @@ Blockly.Python['lists_getSublist'] = function(block) {
var at1 = '';
break;
default:
throw 'Unhandled option (lists_getSublist)';
throw Error('Unhandled option (lists_getSublist)');
}
switch (where2) {
case 'FROM_START':
@@ -298,7 +298,7 @@ Blockly.Python['lists_getSublist'] = function(block) {
var at2 = '';
break;
default:
throw 'Unhandled option (lists_getSublist)';
throw Error('Unhandled option (lists_getSublist)');
}
var code = list + '[' + at1 + ' : ' + at2 + ']';
return [code, Blockly.Python.ORDER_MEMBER];
@@ -349,7 +349,7 @@ Blockly.Python['lists_split'] = function(block) {
Blockly.Python.ORDER_MEMBER) || '\'\'';
var code = value_delim + '.join(' + value_input + ')';
} else {
throw 'Unknown mode: ' + mode;
throw Error('Unknown mode: ' + mode);
}
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
};

View File

@@ -207,5 +207,5 @@ Blockly.Python['controls_flow_statements'] = function(block) {
case 'CONTINUE':
return 'continue\n';
}
throw 'Unknown flow statement.';
throw Error('Unknown flow statement.');
};

View File

@@ -147,7 +147,7 @@ Blockly.Python['math_single'] = function(block) {
code = 'math.atan(' + arg + ') / math.pi * 180';
break;
default:
throw 'Unknown math operator: ' + operator;
throw Error('Unknown math operator: ' + operator);
}
return [code, Blockly.Python.ORDER_MULTIPLICATIVE];
};
@@ -342,7 +342,7 @@ Blockly.Python['math_on_list'] = function(block) {
code = 'random.choice(' + list + ')';
break;
default:
throw 'Unknown operator: ' + func;
throw Error('Unknown operator: ' + func);
}
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
};

View File

@@ -140,7 +140,7 @@ Blockly.Python['text_charAt'] = function(block) {
code = functionName + '(' + text + ')';
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
}
throw 'Unhandled option (text_charAt).';
throw Error('Unhandled option (text_charAt).');
};
Blockly.Python['text_getSubstring'] = function(block) {
@@ -163,7 +163,7 @@ Blockly.Python['text_getSubstring'] = function(block) {
var at1 = '';
break;
default:
throw 'Unhandled option (text_getSubstring)';
throw Error('Unhandled option (text_getSubstring)');
}
switch (where2) {
case 'FROM_START':
@@ -184,7 +184,7 @@ Blockly.Python['text_getSubstring'] = function(block) {
var at2 = '';
break;
default:
throw 'Unhandled option (text_getSubstring)';
throw Error('Unhandled option (text_getSubstring)');
}
var code = text + '[' + at1 + ' : ' + at2 + ']';
return [code, Blockly.Python.ORDER_MEMBER];