002.错误处理与调度

1. @debug

@debug指令打印Sass表达式的值到标准的错误输出流。这对于调试具有复杂Sass表达式的Sass文件非常有用的。 例如:

 @debug 10em + 12em;

输出

Line 1 DEBUG: 22em

2. @warn

@warn指令打印Sass表达式的值到标准的错误输出流。这对于警告用户弃用库 或 修复 mixin 轻微的错误是非常有用的。<kbd>@warn</kbd>和@debug</kbd>之间有两个主要区别:

  • 您可以使用--quiet命令行选项或:quiet Sass选项关闭警告。
  • 样式表跟踪将与消息一起被打印出来,这样,用户可以看到他们的样式在哪里引起了警告。
@mixin adjust-location($x, $y) {
  @if unitless($x) {
    @warn "Assuming #{$x} to be in pixels";
    $x: 1px * $x;
  }
  @if unitless($y) {
    @warn "Assuming #{$y} to be in pixels";
    $y: 1px * $y;
  }
  position: relative; left: $x; top: $y;
}

3. @error

@error指令抛出一个Sass表达式的值作为一个致命的错误,其中包括一个不错的堆栈跟踪。这对于验证混入(mixin)和函数的参数很有用。

@mixin adjust-location($x, $y) {
@if unitless($x) {
  @error "$x may not be unitless, was #{$x}.";
}
@if unitless($y) {
  @error "$y may not be unitless, was #{$y}.";
}
position: relative; left: $x; top: $y;
}

results matching ""

    No results matching ""