Documentation
¶
Overview ¶
Package except provides try-catch-finally exception handling for Go.
This package implements a traditional exception handling mechanism inspired by languages like Java, Python, and JavaScript, allowing developers to use familiar try-catch-finally patterns in Go.
Copyright (c) 2025 mew-sh Licensed under the MIT License. See LICENSE file for details.
Index ¶
- type Exception
- type ExceptionHandler
- func (e *ExceptionHandler) AssertionError(args ...interface{}) *Exception
- func (e *ExceptionHandler) Catch(exceptionTypes []ExceptionType, cb func(excep *Exception)) *ExceptionHandler
- func (e *ExceptionHandler) ConnectionError(args ...interface{}) *Exception
- func (e *ExceptionHandler) EOFError(args ...interface{}) *Exception
- func (e *ExceptionHandler) Finally(cb func()) *ExceptionHandler
- func (e *ExceptionHandler) In(exceptionTypes ...ExceptionType) []ExceptionType
- func (e *ExceptionHandler) IndexError(args ...interface{}) *Exception
- func (e *ExceptionHandler) LookupError(args ...interface{}) *Exception
- func (e *ExceptionHandler) NetworkError(args ...interface{}) *Exception
- func (e *ExceptionHandler) NewException(exceptionType ExceptionType, args ...interface{}) *Exception
- func (e *ExceptionHandler) PermissionError(args ...interface{}) *Exception
- func (e *ExceptionHandler) ReferenceError(args ...interface{}) *Exception
- func (e *ExceptionHandler) Run()
- func (e *ExceptionHandler) RuntimeError(args ...interface{}) *Exception
- func (e *ExceptionHandler) SyntaxError(args ...interface{}) *Exception
- func (e *ExceptionHandler) Throw(exp *Exception)
- func (e *ExceptionHandler) TimeoutError(args ...interface{}) *Exception
- func (e *ExceptionHandler) Try(cb func()) *ExceptionHandler
- func (e *ExceptionHandler) TypeError(args ...interface{}) *Exception
- func (e *ExceptionHandler) UnknownError(args ...interface{}) *Exception
- func (e *ExceptionHandler) ValueError(args ...interface{}) *Exception
- type ExceptionType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exception ¶
type Exception struct { Message string Type ExceptionType StackTrace string }
Exception represents an exception with message, type and stack trace
type ExceptionHandler ¶
type ExceptionHandler struct { // Export exception types for easy access AssertionErrorType ExceptionType IndexErrorType ExceptionType RuntimeErrorType ExceptionType ValueErrorType ExceptionType NetworkErrorType ExceptionType SyntaxErrorType ExceptionType PermissionErrorType ExceptionType TimeoutErrorType ExceptionType TypeErrorType ExceptionType ConnectionErrorType ExceptionType ReferenceErrorType ExceptionType EOFErrorType ExceptionType LookupErrorType ExceptionType UnknownErrorType ExceptionType // contains filtered or unexported fields }
ExceptionHandler is the main handler for try-catch-finally operations
func (*ExceptionHandler) AssertionError ¶
func (e *ExceptionHandler) AssertionError(args ...interface{}) *Exception
AssertionError creates an assertion error exception
func (*ExceptionHandler) Catch ¶
func (e *ExceptionHandler) Catch(exceptionTypes []ExceptionType, cb func(excep *Exception)) *ExceptionHandler
Catch handles exceptions based on the provided exception types
func (*ExceptionHandler) ConnectionError ¶
func (e *ExceptionHandler) ConnectionError(args ...interface{}) *Exception
ConnectionError creates a connection error exception
func (*ExceptionHandler) EOFError ¶
func (e *ExceptionHandler) EOFError(args ...interface{}) *Exception
EOFError creates an EOF error exception
func (*ExceptionHandler) Finally ¶
func (e *ExceptionHandler) Finally(cb func()) *ExceptionHandler
Finally executes the provided function regardless of whether an exception occurred
func (*ExceptionHandler) In ¶
func (e *ExceptionHandler) In(exceptionTypes ...ExceptionType) []ExceptionType
In creates a list of exception types for matching in catch blocks
func (*ExceptionHandler) IndexError ¶
func (e *ExceptionHandler) IndexError(args ...interface{}) *Exception
IndexError creates an index error exception
func (*ExceptionHandler) LookupError ¶
func (e *ExceptionHandler) LookupError(args ...interface{}) *Exception
LookupError creates a lookup error exception
func (*ExceptionHandler) NetworkError ¶
func (e *ExceptionHandler) NetworkError(args ...interface{}) *Exception
NetworkError creates a network error exception
func (*ExceptionHandler) NewException ¶
func (e *ExceptionHandler) NewException(exceptionType ExceptionType, args ...interface{}) *Exception
NewException creates a new Exception with the specified type and optional message
func (*ExceptionHandler) PermissionError ¶
func (e *ExceptionHandler) PermissionError(args ...interface{}) *Exception
PermissionError creates a permission error exception
func (*ExceptionHandler) ReferenceError ¶
func (e *ExceptionHandler) ReferenceError(args ...interface{}) *Exception
ReferenceError creates a reference error exception
func (*ExceptionHandler) Run ¶
func (e *ExceptionHandler) Run()
Run executes the try-catch-finally flow
func (*ExceptionHandler) RuntimeError ¶
func (e *ExceptionHandler) RuntimeError(args ...interface{}) *Exception
RuntimeError creates a runtime error exception
func (*ExceptionHandler) SyntaxError ¶
func (e *ExceptionHandler) SyntaxError(args ...interface{}) *Exception
SyntaxError creates a syntax error exception
func (*ExceptionHandler) Throw ¶
func (e *ExceptionHandler) Throw(exp *Exception)
Throw throws an exception
func (*ExceptionHandler) TimeoutError ¶
func (e *ExceptionHandler) TimeoutError(args ...interface{}) *Exception
TimeoutError creates a timeout error exception
func (*ExceptionHandler) Try ¶
func (e *ExceptionHandler) Try(cb func()) *ExceptionHandler
Try executes the provided function and captures any panics or exceptions
func (*ExceptionHandler) TypeError ¶
func (e *ExceptionHandler) TypeError(args ...interface{}) *Exception
TypeError creates a type error exception
func (*ExceptionHandler) UnknownError ¶
func (e *ExceptionHandler) UnknownError(args ...interface{}) *Exception
UnknownError creates an unknown error exception
func (*ExceptionHandler) ValueError ¶
func (e *ExceptionHandler) ValueError(args ...interface{}) *Exception
ValueError creates a value error exception
type ExceptionType ¶
type ExceptionType string
ExceptionType represents the type of exception
const ( UnknownErrorType ExceptionType = "UnknownError" IndexErrorType ExceptionType = "IndexError" RuntimeErrorType ExceptionType = "RuntimeError" ValueErrorType ExceptionType = "ValueError" NetworkErrorType ExceptionType = "NetworkError" SyntaxErrorType ExceptionType = "SyntaxError" PermissionErrorType ExceptionType = "PermissionError" TimeoutErrorType ExceptionType = "TimeoutError" TypeErrorType ExceptionType = "TypeError" AssertionErrorType ExceptionType = "AssertionError" ConnectionErrorType ExceptionType = "ConnectionError" ReferenceErrorType ExceptionType = "ReferenceError" EOFErrorType ExceptionType = "EOFError" LookupErrorType ExceptionType = "LookupError" )
Predefined exception types