[Vala] Error handling documentation



Hi,
It's seem to not enought documentation at http://live.gnome.org/Vala/Tutorial#Error_Handling about error codes.
I suppose this may help:

/* valac vala_err_code.vala */

errordomain ErrorType1 {
   CODE_1A
}

errordomain ErrorType2 {
   CODE_2A,
   CODE_2B,
   CODE_2C
}

public class Test : GLib.Object {
   public static void thrower() throws ErrorType1, ErrorType2 {
       //throw new ErrorType1.CODE_1A("Error CODE_1A");
       throw new ErrorType2.CODE_2A("Error CODE_2A");
       //throw new ErrorType2.CODE_2B("Error CODE_2B");
       //throw new ErrorType2.CODE_2C("Error CODE_2C");
   }

   public static void catcher() throws ErrorType2 {
       try {
           thrower();
       } catch (ErrorType1 e) {
           // Deal with ErrorType1
           print("Catch ErrorType1\n");
       } finally {
           // Tidy up
       }
   }

   public static int main(string[] args) {
       try {
           catcher();
       } catch (ErrorType2.CODE_2A e) {
           print("Catch ErrorType2.CODE_2A\n");
       } catch (ErrorType2 e) {
           // Deal with ErrorType2
           if (e is ErrorType2.CODE_2B) {
               print("Catch ErrorType2.CODE_2B\n");
           } else
               print("Catch ErrorType2 (code=%d)\n", e.code);
       }
       return 0;
   }
}


--
Роман Харин <HarinRoman 3dsyatoe ru>
jabber://harinr jabber ru




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]