PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 4, 2022

[FIXED] How to catch C++ exception code in iOS Objective-C?

 August 04, 2022     c++, exception, ios, objective-c     No comments   

Issue

I'm new to iOS programming, now I met a problem related to catching the exception code threw from a C++ class.

    @try {
        myCPPClass myObj ; //this throws integer exception codes
    }
    @catch (...) { //I want to catch the integer value here, how ??
        NSLog(@"Exception:") ;
    }
    @finally {
    } 

I knew it maybe not a good practice coding Objective-C in exception catching style, I'd like to know how to make custom exception class for C++ classes in Objective-C ?


Solution

Rename your objective-c .m source files to have the .mm extension. They will then be compiled as objective-c++ which is fully compatible with objective-c while offering all the facilities of c++.

then you can catch c++ exceptions with the usual

try {
   ...
}
catch(std::exception& e) {
   ...
}

construct.



Answered By - Richard Hodges
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing