|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
| 9 | +import {ɵRuntimeError as RuntimeError} from '@angular/core'; |
| 10 | + |
9 | 11 | import { |
10 | 12 | getLocaleNumberFormat, |
11 | 13 | getLocaleNumberSymbol, |
12 | 14 | getNumberOfCurrencyDigits, |
13 | 15 | NumberFormatStyle, |
14 | 16 | NumberSymbol, |
15 | 17 | } from './locale_data_api'; |
| 18 | +import {RuntimeErrorCode} from '../errors'; |
16 | 19 |
|
17 | 20 | export const NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(-(\d+))?)?$/; |
18 | 21 | const MAX_DIGITS = 22; |
@@ -55,7 +58,10 @@ function formatNumberToLocaleString( |
55 | 58 | if (digitsInfo) { |
56 | 59 | const parts = digitsInfo.match(NUMBER_FORMAT_REGEXP); |
57 | 60 | if (parts === null) { |
58 | | - throw new Error(`${digitsInfo} is not a valid digit info`); |
| 61 | + throw new RuntimeError( |
| 62 | + RuntimeErrorCode.INVALID_DIGIT_INFO, |
| 63 | + ngDevMode && `${digitsInfo} is not a valid digit info`, |
| 64 | + ); |
59 | 65 | } |
60 | 66 | const minIntPart = parts[1]; |
61 | 67 | const minFractionPart = parts[3]; |
@@ -436,8 +442,10 @@ function parseNumber(num: number): ParsedNumber { |
436 | 442 | */ |
437 | 443 | function roundNumber(parsedNumber: ParsedNumber, minFrac: number, maxFrac: number) { |
438 | 444 | if (minFrac > maxFrac) { |
439 | | - throw new Error( |
440 | | - `The minimum number of digits after fraction (${minFrac}) is higher than the maximum (${maxFrac}).`, |
| 445 | + throw new RuntimeError( |
| 446 | + RuntimeErrorCode.INVALID_NUMBER_OF_DIGITS_AFTER_FRACTION, |
| 447 | + ngDevMode && |
| 448 | + `The minimum number of digits after fraction (${minFrac}) is higher than the maximum (${maxFrac}).`, |
441 | 449 | ); |
442 | 450 | } |
443 | 451 |
|
@@ -509,7 +517,10 @@ function roundNumber(parsedNumber: ParsedNumber, minFrac: number, maxFrac: numbe |
509 | 517 | export function parseIntAutoRadix(text: string): number { |
510 | 518 | const result: number = parseInt(text); |
511 | 519 | if (isNaN(result)) { |
512 | | - throw new Error('Invalid integer literal when parsing ' + text); |
| 520 | + throw new RuntimeError( |
| 521 | + RuntimeErrorCode.INVALID_INTEGER_LITERAL, |
| 522 | + ngDevMode && 'Invalid integer literal when parsing ' + text, |
| 523 | + ); |
513 | 524 | } |
514 | 525 | return result; |
515 | 526 | } |
0 commit comments