Exception Hierarchy
SolarSharp uses a structured exception hierarchy for different error types:Exception Types
InterpreterException
The base exception class for all SolarSharp errors:Key Properties
Message- Raw error messageDecoratedMessage- Error message with location informationInstructionPtr- Bytecode instruction pointer (if applicable)CallStack- Lua call stack framesDoNotDecorateMessage- Controls message decoration
ScriptRuntimeException
Thrown during script execution for runtime errors:Common Runtime Errors
Type Mismatch Errors:SyntaxErrorException
Thrown during parsing for syntax errors:IsPrematureStreamTermination
Useful for REPL implementations to detect incomplete input:InternalErrorException
Thrown when the interpreter reaches an inconsistent state (rare):Error Handling Patterns
Basic Try-Catch
Detailed Error Logging
Custom Error Handler
Lua Error Function
Triggering Errors from Lua
Catching Errors in Lua
Standard Error Patterns
SolarSharp provides static methods for standard error messages:Arithmetic Errors
Function Argument Errors
Type Conversion Errors
Exception Nesting
Control exception nesting behavior:Best Practices
1. Always Catch Specific Exceptions
2. Use DecoratedMessage
3. Log Call Stacks
4. Validate Input
5. Sandbox Dangerous Operations
Unity-Specific Error Handling
Debugging Tips
Enable Debug Output
Capture Performance Statistics
Custom Error Messages
Provide context-specific error messages:Next Steps
- Explore REPL Usage for interactive error debugging
- Learn about Unity Integration error handling
- Check the API Reference for more details