dev/vala/hello/exception.vala

51 lines
1.1 KiB
Vala
Raw Permalink Normal View History

2012-10-02 14:47:36 +04:00
public errordomain ErrType01
{
ERROR_CODE_01
}
public errordomain ErrType02
{
ERROR_TYPE_02
}
public class MyClass : GLib.Object
{
public static void myfunc_throw() throws ErrType01, ErrType02
{
throw new ErrType01.ERROR_CODE_01( "Ошибка с кодом 01" );
2012-10-02 15:03:48 +04:00
// throw new ErrType02.ERROR_TYPE_02( "Ошибка с типом 02" );
2012-10-02 14:47:36 +04:00
}
public static void myfunc_catch() throws ErrType02
{
try
{
myfunc_throw();
}
catch( ErrType01 e )
{
// Здесь обрабатываются ошибки из домена ErrType01
2012-10-02 15:03:48 +04:00
stdout.printf ("ERR: %s\n", e.message);
2012-10-02 14:47:36 +04:00
}
finally
{
// Освобождение ресурсов и прочие необходимые операции
2012-10-02 15:03:48 +04:00
stdout.printf ("Освобождение ресурсов и прочие необходимые операции.\n");
2012-10-02 14:47:36 +04:00
}
}
public static int main( string[] args )
{
try
{
myfunc_catch();
}
catch( ErrType02 e )
{
// Здесь обрабатываются ошибки из домена ErrType02
2012-10-02 15:03:48 +04:00
stdout.printf ("ERR: %s\n", e.message);
2012-10-02 14:47:36 +04:00
}
return 0;
}
}