fix(errors): [2/2] Rename Exception to Error; remove from public API

BREAKING CHANGE:

Exceptions are no longer part of the public API. We don't expect that anyone should be referring to the Exception types.

ExceptionHandler.call(exception: any, stackTrace?: any, reason?: string): void;
change to:
ErrorHandler.handleError(error: any): void;
This commit is contained in:
Misko Hevery
2016-08-25 00:50:16 -07:00
committed by Victor Berchet
parent 86ba072758
commit 7c07bfff97
142 changed files with 565 additions and 774 deletions

View File

@ -6,59 +6,52 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseWrappedException} from './base_wrapped_exception';
import {ExceptionHandler} from './exception_handler';
export {ExceptionHandler} from './exception_handler';
/**
* @stable
*/
export class BaseException extends Error {
public stack: any;
constructor(public message: string = '--') {
super(message);
this.stack = (<any>new Error(message)).stack;
}
toString(): string { return this.message; }
}
/**
* Wraps an exception and provides additional context or information.
* @stable
*/
export class WrappedException extends BaseWrappedException {
private _wrapperStack: any;
constructor(
private _wrapperMessage: string, private _originalException: any /** TODO #9100 */,
private _originalStack?: any /** TODO #9100 */, private _context?: any /** TODO #9100 */) {
super(_wrapperMessage);
this._wrapperStack = (<any>new Error(_wrapperMessage)).stack;
}
get wrapperMessage(): string { return this._wrapperMessage; }
get wrapperStack(): any { return this._wrapperStack; }
get originalException(): any { return this._originalException; }
get originalStack(): any { return this._originalStack; }
get context(): any { return this._context; }
get message(): string { return ExceptionHandler.exceptionToString(this); }
toString(): string { return this.message; }
}
export function makeTypeError(message?: string): Error {
return new TypeError(message);
}
export function unimplemented(): any {
throw new BaseException('unimplemented');
throw new Error('unimplemented');
}
/**
* @stable
*/
export class BaseError extends Error {
/**
* @internal
*/
_nativeError: Error;
constructor(message: string) {
// Errors don't use current this, instead they create a new instance.
// We have to do forward all of our api to the nativeInstance.
var nativeError = super(message) as any as Error;
this._nativeError = nativeError;
}
get message() { return this._nativeError.message; }
set message(message) { this._nativeError.message = message; }
get name() { return this._nativeError.name; }
get stack() { return (this._nativeError as any).stack; }
set stack(value) { (this._nativeError as any).stack = value; }
toString() { return this._nativeError.toString(); }
}
/**
* @stable
*/
export class WrappedError extends BaseError {
originalError: any;
/**
* @internal
*/
_nativeError: Error;
constructor(message: string, error: any) {
super(`${message} caused by: ${error instanceof Error ? error.message: error }`);
this.originalError = error;
}
get stack() {
return ((this.originalError instanceof Error ? this.originalError : this._nativeError) as any)
.stack;
}
}

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseError} from './errors';
export interface BrowserNodeGlobal {
Object: typeof Object;
Array: typeof Array;
@ -240,14 +242,6 @@ export class StringJoiner {
toString(): string { return this.parts.join(''); }
}
export class NumberParseError extends Error {
name: string;
constructor(public message: string) { super(); }
toString(): string { return this.message; }
}
export class NumberWrapper {
static toFixed(n: number, fractionDigits: number): string { return n.toFixed(fractionDigits); }
@ -257,7 +251,7 @@ export class NumberWrapper {
static parseIntAutoRadix(text: string): number {
var result: number = parseInt(text);
if (isNaN(result)) {
throw new NumberParseError('Invalid integer literal when parsing ' + text);
throw new Error('Invalid integer literal when parsing ' + text);
}
return result;
}
@ -277,8 +271,7 @@ export class NumberWrapper {
return result;
}
}
throw new NumberParseError(
'Invalid integer literal when parsing ' + text + ' in base ' + radix);
throw new Error('Invalid integer literal when parsing ' + text + ' in base ' + radix);
}
// TODO: NaN is a valid literal but is returned by parseFloat to indicate an error.