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. General Programming
  3. C / C++ / MFC
  4. How to handle exception from function as we not develope that fuction() and dont kno what type of exception it will throw

How to handle exception from function as we not develope that fuction() and dont kno what type of exception it will throw

Scheduled Pinned Locked Moved C / C++ / MFC
helpcollaborationtutorial
5 Posts 4 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.
  • A Offline
    A Offline
    ashish8patil
    wrote on last edited by
    #1

    Hello All, consider following code try { function(); } catch(//what typr should expect) { } fuction is develope from other one and he not mention the type of exception he returning.. ///////////////////////////////////////////////////// if i use this code catch(std::exception & s) { cout<<s.what(); } i get error in vs2008 Error is :-- This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Please help , thanks.

    T S 2 Replies Last reply
    0
    • A ashish8patil

      Hello All, consider following code try { function(); } catch(//what typr should expect) { } fuction is develope from other one and he not mention the type of exception he returning.. ///////////////////////////////////////////////////// if i use this code catch(std::exception & s) { cout<<s.what(); } i get error in vs2008 Error is :-- This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Please help , thanks.

      T Offline
      T Offline
      tolw
      wrote on last edited by
      #2

      Use:

      try
      {
      }
      catch(...)
      {
      }

      To catch all exception types. Good luck!

      A 1 Reply Last reply
      0
      • A ashish8patil

        Hello All, consider following code try { function(); } catch(//what typr should expect) { } fuction is develope from other one and he not mention the type of exception he returning.. ///////////////////////////////////////////////////// if i use this code catch(std::exception & s) { cout<<s.what(); } i get error in vs2008 Error is :-- This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Please help , thanks.

        S Offline
        S Offline
        Software_Developer
        wrote on last edited by
        #3

        You left out the throw() operand. Throw tells the compiler that a function could throw an exception and the catch() operand and catches (handles) the exception thrown by the throw() operand. char *buf; try { buf = new char[512]; if( buf == 0 ) throw "Memory allocation failure!"; } catch( char * str ) { cout << "Exception raised: " << str << '\n'; }

        1 Reply Last reply
        0
        • T tolw

          Use:

          try
          {
          }
          catch(...)
          {
          }

          To catch all exception types. Good luck!

          A Offline
          A Offline
          ashish8patil
          wrote on last edited by
          #4

          Thanks for Reaply, But how can I get type of thown exception. whether he is throwing int,char*,of any user define data type. So that I can Identify what type of execption is occur.

          S 1 Reply Last reply
          0
          • A ashish8patil

            Thanks for Reaply, But how can I get type of thown exception. whether he is throwing int,char*,of any user define data type. So that I can Identify what type of execption is occur.

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            You can't...I would suggest you don't use a function if you don't know what its public interface is...and it's exception throwing habits are part of that public interface, so don't use this one...

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

            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