FUNUsageValidation.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2017 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. NS_ASSUME_NONNULL_BEGIN
  16. /** Helper for creating a general exception for invalid usage of an API. */
  17. NSException *FUNInvalidUsage(NSString *exceptionName, NSString *format, ...);
  18. /**
  19. * Macro to throw exceptions in response to API usage errors. Avoids the lint warning you usually
  20. * get when using @throw and (unlike a function) doesn't trigger warnings about not all codepaths
  21. * returning a value.
  22. *
  23. * Exceptions should only be used for programmer errors made by consumers of the SDK, e.g.
  24. * invalid method arguments.
  25. *
  26. * For recoverable runtime errors, use NSError**.
  27. * For internal programming errors, use FSTFail().
  28. */
  29. #define FUNThrowInvalidArgument(format, ...) \
  30. do { \
  31. @throw FUNInvalidUsage(@"FIRInvalidArgumentException", format, ##__VA_ARGS__); \
  32. } while (0)
  33. NS_ASSUME_NONNULL_END