2006/10/24, Max <[EMAIL PROTECTED]>:
[...]
>
>         try {...}
>         catch (Exception e) {
>                 Logger.Log.Debug ("Something went wrong...");
>         }
>
> IIRC c# also allows:
>
>         catch ()
> or
>         catch (MyOwnException)
>
> without defining a variable if it is not needed.
>
> Is there any reason for always putting the e or the ex variables there
> even though they are not used afterwards?

The answer to your question is no; there is no need to declare a
variable name unless you're going to use it (hence the warning).

So:
    catch (MyException ex) { /* Do stuff */ }
is the same as
    catch (MyException) { /* Do stuff */ }
except that you can't use the exception info inside the  { } block.

To catch everything, you'd typically write
    catch { /* Do stuff */ }
which is identical to:
    catch (Exception) { /* Do stuff */  }

Although, as Daniel Naber pointed out in another reply, it's probably
better to declare the variable and then do something useful with it,
such as print it. :-)

Isak
_______________________________________________
Dashboard-hackers mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/dashboard-hackers

Reply via email to