File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Roadmap/10 - EXCEPCIONES/javascript Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ try {
3+ myFunctionUndefined ( )
4+ } catch ( error ) {
5+ console . log ( "There is an error" )
6+ console . log ( error . name )
7+ }
8+
9+ class CustomError extends Error {
10+
11+ constructor ( ) {
12+
13+ super ( "Custom message" ) ;
14+
15+ }
16+ }
17+
18+
19+ function myFunction ( param1 , param2 ) {
20+ if ( param1 <= 3 ) {
21+ throw new CustomError ( ) ;
22+ }
23+ else if ( typeof ( param2 ) != "number" ) {
24+ throw TypeError ( "Int was expected" ) ;
25+ }
26+ else if ( param2 >= 6 ) {
27+ throw Error ( "Value bigger than 6" ) ;
28+ }
29+ }
30+
31+ try {
32+ //myFunction(1,4);
33+ //myFunction(8,"ed");
34+ myFunction ( 8 , 16 ) ;
35+
36+ } catch ( err ) {
37+
38+ console . log ( "Exception name " , err . name ) ;
39+ console . log ( "Exception message " , err . message ) ;
40+ }
41+
42+ console . log ( "Execution finished " )
You can’t perform that action at this time.
0 commit comments