I created a custom pipe in Angular that is supposed to format passed parameters to date format. The pipe contains a try-catch block to handle any errors, but surprisingly the catch block never seems to be executed even when an invalid date is passed.
import {PipeTransform, Pipe} from 'angular2/core';
@Pipe({
name: 'formatDate'
})
export class FormatDatePipe implements PipeTransform {
transform(value: string): any {
let formattedDate: string;
try {
formattedDate = new Date(value).toLocaleDateString();
}
catch (error) {
return value;
}
finally {
return formattedDate;
}
}
Why does the catch block fail to execute when an invalid date is passed through the pipe?