Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Try catch javascript error in whole web application

Try catch javascript error in whole web application

Scheduled Pinned Locked Moved Web Development
questionjavascripthelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kKamel
    wrote on last edited by
    #1

    Hi, i need to write a code that would try catch any sudden javascript error in the whole application. i do not want to write the try catch in every single page, is this doable??if so how can i do it??

    M 1 Reply Last reply
    0
    • K kKamel

      Hi, i need to write a code that would try catch any sudden javascript error in the whole application. i do not want to write the try catch in every single page, is this doable??if so how can i do it??

      M Offline
      M Offline
      Marc Firth
      wrote on last edited by
      #2

      I'm not sure if there is anything to catch errors globally - but you can simply surround the contents of each of your functions in a try catch statement - or better still a function calling error handling function. Something like: <script> my_function(){    //function code here } my_error_handling(e){    alert(e); } call_my_function(){    try{       my_function();    } catch exception (e){       my_error_handling(e);    } } call_my_function(); </script> Then include the script and change it to call any function passed to it.

      Portfolio | Web Design, Web Hosting & IT Support

      K 1 Reply Last reply
      0
      • M Marc Firth

        I'm not sure if there is anything to catch errors globally - but you can simply surround the contents of each of your functions in a try catch statement - or better still a function calling error handling function. Something like: <script> my_function(){    //function code here } my_error_handling(e){    alert(e); } call_my_function(){    try{       my_function();    } catch exception (e){       my_error_handling(e);    } } call_my_function(); </script> Then include the script and change it to call any function passed to it.

        Portfolio | Web Design, Web Hosting & IT Support

        K Offline
        K Offline
        kKamel
        wrote on last edited by
        #3

        yeah i know, but i do not want to catch them pieces by pieces as you said i want to catch them globally so i would prevent any javascript error that suddenly appears in my application.

        M 1 Reply Last reply
        0
        • K kKamel

          yeah i know, but i do not want to catch them pieces by pieces as you said i want to catch them globally so i would prevent any javascript error that suddenly appears in my application.

          M Offline
          M Offline
          Marc Firth
          wrote on last edited by
          #4

          I found this: http://snipplr.com/view.php?codeview&id=19189[^] function handleError() { alert(An error has occurred!'); return true; } window.onerror = handleError; More[^]

          Portfolio | Web Design, Web Hosting & IT Support

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups