mirror of
https://onedev.site.tesses.net/crosslang/crosslangextras
synced 2026-02-09 01:25:46 +00:00
Add std
This commit is contained in:
41
Tesses.CrossLang.Std/src/exception.tcross
Normal file
41
Tesses.CrossLang.Std/src/exception.tcross
Normal file
@@ -0,0 +1,41 @@
|
||||
/^
|
||||
Create a new exception
|
||||
^/
|
||||
func New.Exception(message,$type,$inner)
|
||||
{
|
||||
if(TypeIsString(type))
|
||||
{
|
||||
return {
|
||||
Message = message,
|
||||
InnerException = inner,
|
||||
Type = type,
|
||||
ToString = Std.Internal.Exception.ToString
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {
|
||||
Message = message,
|
||||
InnerException = inner,
|
||||
Type = "Exception",
|
||||
ToString = Std.Internal.Exception.ToString
|
||||
};
|
||||
}
|
||||
}
|
||||
/^Out of range exception^/
|
||||
func New.OutOfRangeException(varName, $inner)
|
||||
{
|
||||
return new Exception($"{varName} is out of range.","OutOfRangeException",inner);
|
||||
}
|
||||
/^Exception ToString^/
|
||||
func Std.Internal.Exception.ToString(this)
|
||||
{
|
||||
var messagePart = $"{this.Type}: {this.Message}";
|
||||
if(this.InnerException != undefined && this.InnerException != null)
|
||||
{
|
||||
var innerEx = this.InnerException.ToString().Replace("\n","\n\t");
|
||||
return $"{messagePart}\nInner exception:\n{innerEx}";
|
||||
}
|
||||
return messagePart;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user