dev/vala/hello/exception.vala

51 lines
1.1 KiB
Vala
Raw Permalink 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.

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" );
// throw new ErrType02.ERROR_TYPE_02( "Ошибка с типом 02" );
}
public static void myfunc_catch() throws ErrType02
{
try
{
myfunc_throw();
}
catch( ErrType01 e )
{
// Здесь обрабатываются ошибки из домена ErrType01
stdout.printf ("ERR: %s\n", e.message);
}
finally
{
// Освобождение ресурсов и прочие необходимые операции
stdout.printf ("Освобождение ресурсов и прочие необходимые операции.\n");
}
}
public static int main( string[] args )
{
try
{
myfunc_catch();
}
catch( ErrType02 e )
{
// Здесь обрабатываются ошибки из домена ErrType02
stdout.printf ("ERR: %s\n", e.message);
}
return 0;
}
}