function checkTheme() {
		var sThemeName = Theming.getTheme();
		var sPath = ThemeManager._getThemePath("sap.ui.core", sThemeName) + "custom.css";
		var bIsStandardTheme = ThemeHelper.isStandardTheme(Theming.getTheme());
		var res = true;

		var aFailedLibs = [];

		if (_customCSSAdded && _themeCheckedForCustom === sThemeName) {
			// include custom style sheet here because it has already been added using sap/ui/dom/includeStyleSheet
			// hence, needs to be checked for successful inclusion, too
			mAllLoadedLibraries[_CUSTOMID] = {};
		}

		function checkLib(lib) {
			var currentRes = ThemeHelper.checkAndRemoveStyle({ prefix: _THEME_PREFIX, id: lib });

			res = res && currentRes;
			if (res) {

				/* as soon as css has been loaded, look if there is a flag for custom css inclusion inside, but only
				 * if this has not been checked successfully before for the same theme
				 */
				// Only need to adjust custom css in case the theme changed or we have no custom.css yet
				if (!_customCSSAdded || _themeCheckedForCustom != sThemeName) {
					// custom css is only supported for custom themes
					if (!bIsStandardTheme && checkCustom(lib)) {
						// load custom css available at sap/ui/core/themename/custom.css
						var sCustomCssPath = sPath;

						// check for configured query parameters and add them if available
						var sLibCssQueryParams = getLibraryCssQueryParams(mAllLoadedLibraries["sap.ui.core"]);
						if (sLibCssQueryParams) {
							sCustomCssPath += sLibCssQueryParams;
						}

						includeStylesheet(sCustomCssPath, _CUSTOMID);
						_customCSSAdded = true;
						Log.debug("ThemeManager: delivered custom CSS needs to be loaded, Theme not yet applied");
						_themeCheckedForCustom = sThemeName;
						res = false;
						return false;
					// only remove custom css in case a custom.css was added
					} else if (_customCSSAdded) {
						// remove stylesheet once the particular class is not available (e.g. after theme switch)
						/*check for custom theme was not successful, so we need to make sure there are no custom style sheets attached*/
						var oCustomCssLink = document.querySelector("LINK[id='" +  _CUSTOMID + "']");
						if (oCustomCssLink) {
							oCustomCssLink.remove();
							Log.debug("ThemeManager: Custom CSS removed");
						}
						_customCSSAdded = false;
					}

				}
			}

			// Collect all libs that failed to load and no fallback has been applied, yet.
			// The fallback relies on custom theme metadata, so it is not done for standard themes
			if (!bIsStandardTheme && currentRes && !_mThemeFallback[lib]) {
				var oStyle = document.getElementById(`${_THEME_PREFIX}${lib}`);
				// Check for error marker (data-sap-ui-ready=false) and that there are no rules
				// to be sure the stylesheet couldn't be loaded at all.
				// E.g. in case an @import within the stylesheet fails, the error marker will
				// also be set, but in this case no fallback should be done as there is a (broken) theme
				if (oStyle && oStyle.getAttribute("data-sap-ui-ready") === "false" &&
					!(oStyle.sheet && ThemeHelper.hasSheetCssRules(oStyle.sheet))
				) {
					aFailedLibs.push(lib);
				}
			}

		}

		each(mAllLoadedLibraries, checkLib);

		// Try to load a fallback theme for all libs that couldn't be loaded
		if (aFailedLibs.length > 0) {
			// Only retrieve the fallback theme once per ThemeManager cycle
			if (!_sFallbackTheme) {
				for (var sLib in mAllLoadedLibraries) {
					var oThemeMetaData = ThemeHelper.getMetadata(sLib);
					if (oThemeMetaData && oThemeMetaData.Extends && oThemeMetaData.Extends[0]) {
						_sFallbackTheme = oThemeMetaData.Extends[0];
					} else {
						const sThemeRoot = Theming.getThemeRoot(sThemeName, sLib);
						if (sThemeRoot) {
							const rBaseTheme = /~v=[^\/]+\(([a-zA-Z0-9_]+)\)/;
							// base theme should be matched in the first capturing group
							_sFallbackTheme = rBaseTheme.exec(sThemeRoot)?.[1];
							// pass derived fallback theme through our default theme handling
							// in case the fallback theme is not supported anymore, we fall up to the latest default theme
							if (_sFallbackTheme) {
								_sFallbackTheme = ThemeHelper.validateAndFallbackTheme(_sFallbackTheme);
							}
						}
					}

					if (_sFallbackTheme) {
						break;
					}
				}
			}

			if (_sFallbackTheme) {
				aFailedLibs.forEach(function(lib) {
					const oStyle = document.getElementById(`${_THEME_PREFIX}${lib}`);

					Log.warning(
						"ThemeManager: Custom theme '" + sThemeName + "' could not be loaded for library '" + lib + "'. " +
						"Falling back to its base theme '" + _sFallbackTheme + "'."
					);

					// Change the URL to load the fallback theme
					updateThemeUrl(oStyle, _sFallbackTheme);

					// remember the lib to prevent doing the fallback multiple times
					// (if the fallback also can't be loaded)
					_mThemeFallback[lib] = true;
				});

				// Make sure to wait for the fallback themes to be loaded
				res = false;
			}
		}

		if (!res) {
			Log.debug("ThemeManager: Theme not yet applied.");
		} else {
			_themeCheckedForCustom = sThemeName;
		}
		return res;
	}
Notify theme change

@private
@ui5-restricted sap.ui.core