Catch an Exception with a try/catch Block : try catch « Statement « Visual C++ .NET






Catch an Exception with a try/catch Block

 

#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
void MyFunction() {
    int x,y,z;
    x = Int32::Parse(Console::ReadLine());
    y = Int32::Parse(Console::ReadLine());
    z = x/y;
    Console::WriteLine(z);
}
int main(void)
{
    try {
        MyFunction();
    }
    catch (...) {
        Console::WriteLine(
            "Exception. Unable to complete the operation.");
    }
    return 0;
} 

   
  








Related examples in the same category

1.Catch All exceptions
2.Catch Exception
3.Multi Exception Handling
4.Catch IndexOutOfRangeException
5.Catch IO exception
6.Nested exception catching
7.Catch custom exception and then general exception