Skip to content

API Host Exceptions

Liu.Yandong.Hanks edited this page Aug 19, 2026 · 3 revisions

Exceptions and Diagnostics

编译、运行时与源码位置错误

Compilation, runtime, and source-location errors

.NET Host API 目录

概述

AuroraScript 的异常层次以 AuroraException 为基础。编译失败使用 AuroraCompilationException 及诊断列表;运行失败使用 AuroraRuntimeException 及脚本栈帧。

AuroraScript's exception hierarchy starts with AuroraException. Compilation failures use AuroraCompilationException and its diagnostics; runtime failures use AuroraRuntimeException and script stack frames.

AuroraException() / AuroraException(message[, innerException])

Parameters:

  • message
    错误描述。

    Error description.

  • innerException
    可选内部异常。

    Optional inner exception.

Returns

基础引擎异常。

Base engine exception.

throw new AuroraException("Engine configuration is invalid.");

AuroraCompilationException(diagnostics)

Parameters:

  • diagnostics
    一个或多个 AuroraCompilationDiagnostic

    One or more diagnostics.

Returns

聚合编译异常。

Aggregate compilation exception.

try
{
    await engine.BuildAsync("main.as");
}
catch (AuroraCompilationException ex)
{
    Console.WriteLine(ex.FirstDiagnostic);
}

Diagnostics / Count / FirstDiagnostic / FileName / LineNumber / ColumnNumber / ToString()

用途

从编译异常读取全部或首个诊断,以及便于显示的文件和位置。

Read all or first compilation diagnostic and display-friendly file/location details.

catch (AuroraCompilationException ex)
{
    Console.WriteLine($"{ex.FileName}:{ex.LineNumber}:{ex.ColumnNumber}");
    Console.WriteLine(ex.Diagnostics[0].Message);
}

AuroraCompilationDiagnostic

成员

MessageLocationFileNameLineNumberColumnNumberToString() 分别给出错误文本、SourceSpan 和展示位置。

Provide error text, SourceSpan, and display location.

AuroraCompilationDiagnostic diagnostic = ex.FirstDiagnostic;
Console.WriteLine(diagnostic.ToString());

AuroraRuntimeException(message | error | exception, stackTrace)

Parameters:

  • messageScriptError 或原始异常与脚本栈。

    Message, ScriptError, or underlying exception with script stack.

Returns

带脚本上下文的运行时异常。

Runtime exception with script context.

try
{
    domain.Execute("MAIN", "run");
}
catch (AuroraRuntimeException ex)
{
    Console.WriteLine(ex.ToString());
}

ModuleName / LineNumber / StackTrace / ToString()

用途

显示运行错误来源、行号和脚本调用栈。

Display runtime error origin, line, and script call stack.

catch (AuroraRuntimeException ex)
{
    Console.WriteLine($"{ex.ModuleName}:{ex.LineNumber}");
    foreach (var frame in ex.StackTrace) Console.WriteLine(frame);
}

SourceSpan

成员

NoneStartLineStartColumnEndLineEndColumnOffsetLengthFileNameToString() 描述源码范围。

Describe source range.

var location = diagnostic.Location;
Console.WriteLine($"{location.FileName}:{location.StartLine}:{location.StartColumn}");

AuroraStackTrace(path, method, line)

Parameters:

  • path
    脚本路径。

    Script path.

  • method
    方法名。

    Method name.

  • line
    行号。

    Line number.

成员

FileNameFullPathMethodLineToString()

File name, full path, method, line, and formatter.

var frame = new AuroraStackTrace("scripts/main.as", "run", 12);
Console.WriteLine(frame.ToString());

Clone this wiki locally