Possible "throws" syntax

Marco Leise Marco.Leise at gmx.de
Sat Aug 11 20:28:35 PDT 2012


Am Sun, 12 Aug 2012 05:02:25 +0200
schrieb Marco Leise <Marco.Leise at gmx.de>:

> ---D->>
> 
> /**
>  * Receives a response from the server.
>  * 
>  * Some explanation of what
>  * the function does in detail.
>  * 
>  * Params:
>  *    response = receives the whole response
>  * Throws: 
>  *    UnexpectedResponseException if the server sent us garbage
>  *
>  *    UnauthenticatedException we need retry after we have logged in
>  *
>  *    SecurityException we have to switch to a secure connection for this
>  *
>  *    DisconnectException the connection was unexpectedly terminated
>  * Returns: the associated response code
>  */
> int foo(out string response)
> {...}
> 
> <<-D---

could become:

---D->>

/**
 * Receives a response from the server.
 * 
 * Some explanation of what
 * the function does in detail.
 * 
 * Params:
 *    response = receives the whole response
 * Returns: the associated response code
 */
int foo(out string response) throws
    UnexpectedResponseException, /// if the server sent us garbage
    UnauthenticatedException, /// we need retry after we have logged in
    SecurityException, /// we have to switch to a secure connection for this
    DisconnectException /// the connection was unexpectedly terminated
{...}

<<-D--

So there would be no net change in typing required if that is a concern. Callers of the function could inherit from this documentation as well for their "throws" section, so you only have to rewrite the documetation if the reason for the exception needs to be formulated differently or multiple called functions throw the same exception.

-- 
Marco



More information about the Digitalmars-d mailing list