FSTUsageValidation.h 1.7 KB

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