Blog

  • Home
  • iPhone
  • Objective C – Exception handling In iPhone

Objective C – Exception handling In iPhone

  • (4.0)
  • | 1159 Ratings

The exception handling mechanisms available to OBJECTIVE-C programs are effective ways of dealing with exceptional conditions. They decouple the detection and handling of these conditions and automate the propagation of the exception from the point of detection to the point of handling. As a result, your code can be much cleaner, easier to write correctly, and easier to maintain.

Looking for IOS Training? Mindmajix Offers Best IOS Developer Training With Industry Experts.

Exception are generated at runtime and these are runtime, error, objective c language as a exception handling syntax similar to c++, java and here we use NS exception, NS error.
An exception is a special condition, but interrupts normal flow of execution objective c has four exception compiler directives. They are.

@try
@catch
@finally
@throws

try black:-

try black holds code that can potentially throw an exception which is enclosed in a try black.

Syntax:-  

@try
{
Int  x;
   Scan f (  “%d”,    &x);

Int y =  2/x;
}

Catch block:-

 A catch block contains exception handling logic for exception throw in a try block. We can have multiple catch block for single try block.

Syntax:-  

 @  catch (NS argument exception * aex)
{
   }
@catch(NS exception   *  ex)
{
   }

finally block:-    

This block is optional and it contains a code for declaration of resources .

Syntax:-   

@finally
{
}

Note:-

 NS exception classes the base class for all the exception related classes.

Throws:-

By using throws, we can rise over own exception.


Frequently Asked iPhone Interview Questions & Answers


Subscribe For Free Demo

Free Demo for Corporate & Online Trainings.

Ravindra Savaram
About The Author

Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.


DMCA.com Protection Status

Close
Close