W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
錯誤,與提示有所不同,將會中斷編譯器的下一步進程。基本上,它們中斷編譯并像堆棧跟蹤一樣在輸出流中顯示相關信息,這對調試很有幫助。因此,如果程序無法繼續(xù)執(zhí)行就應該拋出錯誤。如有可能,嘗試解決這個問題并以顯示提醒的方式代替。
舉個例子,假設你創(chuàng)建了一個 getter 函數來從特定 map 中獲取值。如果想要獲取的值并不在 map 中,就可能會拋出錯誤。
/// Z-indexes map, gathering all Z layers of the application
/// @access private
/// @type Map
/// @prop {String} key - Layer’s name
/// @prop {Number} value - Z value mapped to the key
$z-indexes: (
'modal': 5000,
'dropdown': 4000,
'default': 1,
'below': -1,
);
/// Get a z-index value from a layer name
/// @access public
/// @param {String} $layer - Layer's name
/// @return {Number}
/// @require $z-indexes
@function z($layer) {
@if not map-has-key($z-indexes, $layer) {
@error 'There is no layer named `#{$layer}` in $z-indexes. '
+ 'Layer should be one of #{map-keys($z-indexes)}.';
}
@return map-get($z-indexes, $layer);
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: