티스토리 뷰
Exception handling in C++
Exception handling is the method you use to make the program work normally under abnormal circumstances(with different errors) but Try, Throw and Catch can't replace every error handling circumstance because it could cause poor performance. It is good to use for the situation which happened difficult to predict the result. But, Try, Throw and Catch strictly handle type conversion.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> #include <string> using namespace std; int main() { int a, b; cout << "Input two numbers: "; cin >> a >> b; try // Code which could cause exception { if (b < 1 || a < 1) { throw string("Error occured"); //throw - throw an exception } cout << a << " can not be devided by " << b << " , " << a / b << endl; } catch (string errMessage) //catch - catches an exception with an exception handler { cout << errMessage << endl; } return 0; } | cs |
Result
'C++' 카테고리의 다른 글
Friend in C++ (0) | 2018.11.22 |
---|---|
Templates (Function Template & Class Template) in C++ (0) | 2018.11.10 |
Inline function in C++ (0) | 2018.11.09 |
Copy constructor(Deep copy, Shallow copy) in C++ (0) | 2018.11.09 |
Inheritance and Overriding in C++ with simple example (0) | 2018.11.07 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 프로그래머스
- string class in java
- javascript
- math.abs
- easy javascript algorithm
- HackerRank Algorithm
- hackerrank javascript solution
- C++
- algorithm
- equals()
- math.max
- hackerrank
- Javascript Algorithm
- hackerrank javascript
- java
- Object type casting
- substring()
- easy algorithm
- rest parameter
- 프로그래머스 알고리즘문제
- Collection Framework
- compareTo()
- 프로그래머스 알고리즘
- HashMap
- code refactoring
- ... in Javascript
- spring boot application
- hackerrank solution
- 알고리즘
- repeat()
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
글 보관함