throw                  package:R.oo                  R Documentation

_T_h_r_o_w_s _a_n _E_x_c_e_p_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Throws an exception similar to stop(), but with support for
     exception classes. The first argument ('object') is by default
     pasted together with other arguments ('...') and with seperator
     'sep=""'. For instance, to throw an exception, write

     'throw("Value out of range: ", value, ".")'.

     which is short for

     'throw(Exception("Value out of range: ", value, "."))'.

     Note that 'throw()' can be defined for specific classes, which can
     then be caught (or not) using 'tryCatch'().

_U_s_a_g_e:

     ## Default S3 method:
     throw(...)

_A_r_g_u_m_e_n_t_s:

     ...: One or several strings that are concatenated and collapsed
          into on message string.

_V_a_l_u_e:

     Returns nothing.

_A_u_t_h_o_r(_s):

     Henrik Bengtsson (<URL: http://www.braju.com/R/>)

_S_e_e _A_l_s_o:

     See the 'Exception' class for more detailed information.

_E_x_a_m_p_l_e_s:

       rbern <- function(n=1, prob=1/2) {
         if (prob < 0 || prob > 1)
           throw("Argument 'prob' is out of range: ", prob)
         rbinom(n=n, size=1, prob=prob)
       }

       rbern(10, 0.4)
       # [1] 0 1 0 0 0 1 0 0 1 0
       tryCatch(rbern(10, 10*0.4),
         error=function(ex) {}
       )

