Handling unhandled errors better.
Now the Unhandled error contains the errno value for reference.
This commit is contained in:
parent
a320296f18
commit
32ed0dd881
@ -43,6 +43,9 @@ pub enum CError
|
|||||||
/// There was a detected error, but it
|
/// There was a detected error, but it
|
||||||
/// is not one handled by CError.
|
/// is not one handled by CError.
|
||||||
Unhandled
|
Unhandled
|
||||||
|
{
|
||||||
|
errno: i32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -53,11 +56,18 @@ impl CError
|
|||||||
pub fn is_handled_error(errno: i32) -> bool
|
pub fn is_handled_error(errno: i32) -> bool
|
||||||
{
|
{
|
||||||
let error: CError;
|
let error: CError;
|
||||||
|
let unhandled: CError;
|
||||||
|
|
||||||
|
// Create an error that would be if this was unhandled.
|
||||||
|
unhandled = CError::Unhandled
|
||||||
|
{
|
||||||
|
errno: errno
|
||||||
|
};
|
||||||
|
|
||||||
// Turn the error value into a CError and
|
// Turn the error value into a CError and
|
||||||
// check if it is an Unhandled error.
|
// check if it is an Unhandled error.
|
||||||
error = CError::from(errno);
|
error = CError::from(errno);
|
||||||
if error != CError::Unhandled
|
if error != unhandled
|
||||||
{
|
{
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@ -76,7 +86,7 @@ impl CError
|
|||||||
/// Set the current Error for the system.
|
/// Set the current Error for the system.
|
||||||
pub fn set_current_error(error: CError)
|
pub fn set_current_error(error: CError)
|
||||||
{
|
{
|
||||||
set_errno(error as i32);
|
set_errno(error.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear the current Error.
|
/// Clear the current Error.
|
||||||
@ -113,7 +123,22 @@ impl From<i32> for CError
|
|||||||
EDOM => { CError::Domain }
|
EDOM => { CError::Domain }
|
||||||
ERANGE => { CError::Range }
|
ERANGE => { CError::Range }
|
||||||
EILSEQ => { CError::IllegalSequence }
|
EILSEQ => { CError::IllegalSequence }
|
||||||
_ => { CError::Unhandled }
|
_ => { CError::Unhandled { errno: val } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<i32> for CError
|
||||||
|
{
|
||||||
|
fn into(self) -> i32
|
||||||
|
{
|
||||||
|
match self
|
||||||
|
{
|
||||||
|
CError::None => { NO_ERROR }
|
||||||
|
CError::Domain => { EDOM }
|
||||||
|
CError::Range => { ERANGE }
|
||||||
|
CError::IllegalSequence => { EILSEQ }
|
||||||
|
CError::Unhandled { errno: val } => { val }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +153,8 @@ impl Error for CError
|
|||||||
CError::Domain => { "Math argument out of domain of function" }
|
CError::Domain => { "Math argument out of domain of function" }
|
||||||
CError::Range => { "Math result not representable" }
|
CError::Range => { "Math result not representable" }
|
||||||
CError::IllegalSequence => { "Illegal byte sequence" }
|
CError::IllegalSequence => { "Illegal byte sequence" }
|
||||||
CError::Unhandled => { "Detected an Error not handled by CError" }
|
CError::Unhandled { errno: _val } =>
|
||||||
|
{ "Detected an Error not handled by CError" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user