Calls `f` in a try/except block, returning a `Fail` object if
    the call fails in any way. If any of the arguments to the call are Fail
    objects, the call is not attempted.
545114
def maybe(func):
    """"""

    name = object_name(func)

    @wraps(func)
    def maybe_wrapped(*args, **kwargs):
        """@maybe wrapped version of ``func``."""
        fails = [
            (name, k, v)
            for k, v in chain(enumerate(args), kwargs.items())
            if isinstance(v, Fail)]

        if fails:
            return Fail(func, fails=fails)

        try:
            result = func(*args, **kwargs)

        except Exception as exc:
            return Fail(func, exception=exc)

        else:
            if isinstance(result, Fail):
                result.add_call(func)

            return result

    return maybe_wrapped
482417
def _catch(f, exception_type):
  """"""
  if not (inspect.isclass(exception_type)
          and issubclass(exception_type, Exception)):
    exception_type = Exception

  @functools.wraps(f)
  def wrap(*args, **kw):
    try:
      return f(*args, **kw)
    except exception_type as e:  # pylint: disable=broad-except
      qj(e, 'Caught an exception in %s' % f, d=1, _depth=2)
  return wrap
1300979
def retry(ExceptionToCheck, tries=3, delay=2, backoff=2):
    
    def deco_retry(f):
        def f_retry(*args, **kwargs):
            mtries, mdelay = tries, delay
            try_one_last_time = True
            while mtries > 1:
                try:
                    return f(*args, **kwargs)
                    try_one_last_time = False
                    break
                except ExceptionToCheck:
                    six.print_("Retrying in %s seconds" % str(mdelay))
                    time.sleep(mdelay)
                    mtries -= 1
                    mdelay *= backoff
            if try_one_last_time:
                return f(*args, **kwargs)
            return
        return f_retry  # true decorator
    return deco_retry
390840
function tryCatch(fnc, context, args) {

		try {
			// Start execusting the function
			switch (args.length) {
				// Avoid apply for up to 3 arguments
				case 1:
					fnc.call(context, args[0]);
					break;
				case 2:
					fnc.call(context, args[0], args[1]);
					break;
				case 3:
					fnc.call(context, args[0], args[1], args[2]);
					break;
				case 4:
					fnc.call(context, args[0], args[1], args[2], args[3]);
					break;
				// Use the slower apply
				default:
					fnc.apply(context, args);
			}
		} catch (err) {
			return err;
		}

		return null;
	}
792452
def exception(function):
    
    @functools.wraps(function)
    def wrapper(*exception, **kwargs):
        result = function(**kwargs)
        if exception:
            result.exception = exception[0]
        return result
    return wrapper
43205
def CATCH(exception_klass, &block)
      block.call
    rescue ::Exception
      if $!.instance_of? exception_klass
        pass
      else
        failure("Faced a exception, that instance of #{exception_klass}.",
                "Faced a exception, that instance of #{$!.class}.", 2)
      end
    else
      failure("Faced a exception, that instance of #{exception_klass}.",
              'The block was not faced any exceptions.', 2)
    ensure
      _declared!
    end
662012
boolean failure(Throwable failure) {
        State<T> oldState;
        synchronized (mutex) {
            if (state.isCompleted()) {
                return false;
            }
            oldState = state;
            state = state.getFailureState(failure);
        }
        oldState.callFailureCallbacks(failure);
        return true;
    }
862365
def no_exception(on_exception, logger=None):
    

    def decorator(function):
        def wrapper(*args, **kwargs):
            try:
                result = function(*args, **kwargs)
            except Exception, e:
                if hasattr(logger, 'exception'):
                    logger.exception(e)
                else:
                    print traceback.format_exc()
                result = on_exception
            return result

        return wrapper

    return decorator
1082137
def delete_file(f, ignore_errors=False):
	
	try:
		os.remove(f)
	except Exception as ex:
		if ignore_errors:
			return
		print('ERROR deleting file ' + str(ex))
125225
def mongo_retry(f):
    
    log_all_exceptions = 'arctic' in f.__module__ if f.__module__ else False

    @wraps(f)
    def f_retry(*args, **kwargs):
        global _retry_count, _in_retry
        top_level = not _in_retry
        _in_retry = True
        try:
            while True:
                try:
                    return f(*args, **kwargs)
                except (DuplicateKeyError, ServerSelectionTimeoutError) as e:
                    # Re-raise errors that won't go away.
                    _handle_error(f, e, _retry_count, **_get_host(args))
                    raise
                except (OperationFailure, AutoReconnect) as e:
                    _retry_count += 1
                    _handle_error(f, e, _retry_count, **_get_host(args))
                except Exception as e:
                    if log_all_exceptions:
                        _log_exception(f.__name__, e, _retry_count, **_get_host(args))
                    raise
        finally:
            if top_level:
                _in_retry = False
                _retry_count = 0
    return f_retry
1366521
def handle_api_exception(f):
    
    def wraps(self, *args, **kwargs):
        try:
            return f(self, *args, **kwargs)
        except SupersetSecurityException as e:
            logging.exception(e)
            return json_error_response(utils.error_msg_from_exception(e),
                                       status=e.status,
                                       stacktrace=traceback.format_exc(),
                                       link=e.link)
        except SupersetException as e:
            logging.exception(e)
            return json_error_response(utils.error_msg_from_exception(e),
                                       stacktrace=traceback.format_exc(),
                                       status=e.status)
        except Exception as e:
            logging.exception(e)
            return json_error_response(utils.error_msg_from_exception(e),
                                       stacktrace=traceback.format_exc())
    return functools.update_wrapper(wraps, f)
1329552
def ensure_connected(f):
        
        @functools.wraps(f)
        def wrapper(*args):
            self = args[0]
            self.invalid()
            try:
                return f(*args)
            finally:
                self.invalid()
        return wrapper
1233202
def try_catch(func, *args, **kwargs):
    '''
    
    '''
    try:
        return log_debug(func, *args, **kwargs)
    except Exception as exc:
        logging.debug('Error in "%s" in thread %s: %s', func.__name__, current_thread(), exc)
        return exc
1127967
def spiceFoundExceptionThrower(f):
    
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        res = f(*args, **kwargs)
        if config.catch_false_founds:
            found = res[-1]
            if isinstance(found, bool) and not found:
                raise stypes.SpiceyError("Spice returns not found for function: {}".format(f.__name__), found=found)
            elif hasattr(found, '__iter__') and not all(found):
                raise stypes.SpiceyError("Spice returns not found in a series of calls for function: {}".format(f.__name__), found=found)
            else:
                actualres = res[0:-1]
                if len(actualres) == 1:
                    return actualres[0]
                else:
                    return actualres
        else:
            return res

    return wrapper
1184864
def try_call(self, client_data=None, api_data=None, aux_data=None, *args, **kwargs):
        
        try:
            return self.call(client_data, api_data, aux_data, *args, **kwargs)
        except Exception as e:
            self.last_exception = RequestFailed(cause=e)
        return None
1294233
def wraps(self, f):
        
        @_utils.wraps(f)
        def wrapped_f(*args, **kw):
            return self.call(f, *args, **kw)

        def retry_with(*args, **kwargs):
            return self.copy(*args, **kwargs).wraps(f)

        wrapped_f.retry = self
        wrapped_f.retry_with = retry_with

        return wrapped_f
800894
def exception(function):
    
    @functools.wraps(function)
    def wrapper(*args, **kwargs):
        try:
            return function(*args, **kwargs)
        except Exception as e:
            # print 
            err = "There was an exception in %s():"%(function.__name__)
            print(("%s \n %s \n%s"%(err,e,sys.exc_info())))
            return -1
 
    return wrapper