dlang-book/03-инструкции/src/chapter-3-11/app.d

30 lines
937 B
D
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 1. Объявите класс, который наследуется от Exception.
* 2. Создайте конструктор, который принимает, как минимум, два параметра: string file и
* size_t line, со значениями по умолчанию __FILE__ и __LINE__ соответственно.
* 3. Попросите конструктора переслать аргументы конструктору исключения (super).
* 4. Используйте свое исключение.
*/
class MyException : Exception
{
this (string message, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
{
super(message, file, line, next);
}
}
void main()
{
import std.stdio;
try
{
throw new MyException("message here");
}
catch(MyException e)
{
writeln("caught ", e);
}
}