function throwException( ){ (void 0)() } throwException()
function throwError( ){<br> throw new Error( 'error' )<br>}<br>throwError()<br>
- Something blurted and that's it.var Error= new function ( Original ){<br><br>Version: 1<br>Description: "repairs mozilla's stacktrace in custom errors" <br>License: 'public domain' <br><br>Implementation:<br><br> var Error= ( window.console && Original && ( new Original ).stack )<br>? function ( message ){<br> var e= new Original( message )<br> var custom= function ( msg, file, line ){<br> restore()<br> if ( other && other.apply( this , arguments ) ) return true <br> if (( e.message != msg )||( e.fileName != file )||( e.lineNumber != line )) return <br> var stack= e.stack.split( '\n' )<br> stack= stack.slice( 2, stack.length - 1 )<br> stack[0].replace( /^.*\(.+?\)@(.+):(\d+)$/, function ( str, file, line ){<br> e.fileName= file<br> e.lineNumber= Number( line )<br> })<br> stack[ stack.length - 1 ]= stack[ stack.length - 1 ].replace( /^@.+:\d+$/, function ( str ){<br> return 'source file()' + str<br> })<br> e.stack= stack.join( '\n' )<br> console.error( e )<br> return true <br> }<br> var other= window.onerror<br> var restore= function (){<br> if ( window.onerror === custom ) window.onerror= other<br> }<br> window.onerror= custom<br> setTimeout( restore, 1 )<br> return e<br> }<br>: Original<br><br>Export: return Error<br><br>Usage: throw new Error( 'custom error' )<br><br>}( window.Error )<br>
- What are you whispering to him?Source: https://habr.com/ru/post/87098/
All Articles