Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

미시Cpp/0511: Difference between revisions

From ZeroWiki
imported>computer6561
No edit summary
imported>nerumin90
No edit summary
Line 43: Line 43:
= 스터디 진행 =
= 스터디 진행 =
== 내용 ==
== 내용 ==
 
* unexpected_handler
** throw 리스트에 명시되지 않은 throw가 발생했을 때 발생한다.
* terminate_handler
** 예외 처리가 도저히 불가능할 때 발생하는 것으로, 일단 발생하고 나면 회생 절차가 없다.
== 코드 ==
== 코드 ==
 
* Try/Catch/Throw
 
#include <iostream>
#include <exception>
class Test
{
public:
int invokeException() throw ()
{
throw std::exception();
}
};
int main(void)
{
Test t;
try
{
t.invokeException();
}
catch (std::exception e)
{
std::cout << "Catch!" << std::endl;
}
return 0;
}
* Stack unwinding
class CustomException
{
public:
void testMethod() throw(std::exception);
};
class CustomExceptionChild : public CustomException
{
public:
void testMethod() throw(std::exception);
};
class CustomeExceptionChildChild : public CustomExceptionChild
{
public:
void testMethod() throw(std::exception);
};
  // 자식 클래스에서 예외가 발생했음에도 불구하고 catch 구문이 없을 때, 작업을 중단하고 catch 구문을 발견할 때까지 부모 클래스로 예외 처리가 전달되는 현상.
* throw 리스트와 nothrow
class CustomException
{
public:
static void Test() _NOEXCEPT; // 예외가 발생하지 않음을 보장합니다.
void ExceptTest() throw ();  // throw 리스트 내부에 있는 예외가 발생할 수 있습니다.
};
  // _NOEXCEPT를 선언했는데 예외가 발생할 경우... 재밌는 일이 일어납니다.
* std::exception
class MyException : public std::exception
{
public:
const char * what() const _NOEXCEPT
{
  return "Oooops!\n";
}
};
// std::exception에 들어있는 what 메서드가 중심.
= 잡담 =
= 잡담 =
* 아....체스가 있었지 - [[유재범]]
* 아....체스가 있었지 - [[유재범]]

Revision as of 02:51, 1 June 2015

  다시 출발합니다

미시Cpp

회차 : 5회차 시간 : 11시 30분 ~ 장소 : 6층

참가원

멘토 장용운 출석
멘티 유재범 출석
신형철 출석

이번에 배울 것

템플릿 기초

  • 템플릿의 기본
  • 함수 템플릿과 템플릿 함수
  • 템플릿 클래스
  • 데이터 타입이 아닌 템플릿 파라미터

예외 처리 기초

  • 예외 처리 문법
 ○ try~catch
 ○ throw
  • stack unwinding
  • throw 리스트
  • 함수 또는 메서드에서의 nothrow
  • unexpected_handler, terminate_handler
  • std::exception

실습

  • 체스 프로그램 틀 잡기

스터디 진행

내용

  • unexpected_handler
    • throw 리스트에 명시되지 않은 throw가 발생했을 때 발생한다.
  • terminate_handler
    • 예외 처리가 도저히 불가능할 때 발생하는 것으로, 일단 발생하고 나면 회생 절차가 없다.

코드

  • Try/Catch/Throw
#include <iostream>
#include <exception>

class Test
{
public:
	int invokeException() throw ()
	{
		throw std::exception();
	}
};

int main(void)
{
	Test t;

	try
	{
		t.invokeException();
	}
	catch (std::exception e)
	{
		std::cout << "Catch!" << std::endl;
	}

	return 0;
}
  • Stack unwinding
class CustomException
{
public:
	void testMethod() throw(std::exception);
};

class CustomExceptionChild : public CustomException
{
public:
	void testMethod() throw(std::exception);
};

class CustomeExceptionChildChild : public CustomExceptionChild
{
public:
	void testMethod() throw(std::exception);
};
 // 자식 클래스에서 예외가 발생했음에도 불구하고 catch 구문이 없을 때, 작업을 중단하고 catch 구문을 발견할 때까지 부모 클래스로 예외 처리가 전달되는 현상.
  • throw 리스트와 nothrow
class CustomException
{
public:
	static void Test() _NOEXCEPT; // 예외가 발생하지 않음을 보장합니다.
	void ExceptTest() throw ();   // throw 리스트 내부에 있는 예외가 발생할 수 있습니다.
};
 // _NOEXCEPT를 선언했는데 예외가 발생할 경우... 재밌는 일이 일어납니다.
  • std::exception
class MyException : public std::exception
{
public:
	const char * what() const _NOEXCEPT
	{
		  return "Oooops!\n";
	}
};

// std::exception에 들어있는 what 메서드가 중심.

잡담


활동지도/2015 미시Cpp