Handling unhandled errors better.

Now the Unhandled error contains the errno value for reference.
This commit is contained in:
Myrddin Dundragon 2017-03-11 13:08:02 -05:00
parent a320296f18
commit 32ed0dd881

View File

@ -43,6 +43,9 @@ pub enum CError
/// There was a detected error, but it
/// is not one handled by CError.
Unhandled
{
errno: i32
}
}
@ -53,11 +56,18 @@ impl CError
pub fn is_handled_error(errno: i32) -> bool
{
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
// check if it is an Unhandled error.
error = CError::from(errno);
if error != CError::Unhandled
if error != unhandled
{
true
}
@ -76,7 +86,7 @@ impl CError
/// Set the current Error for the system.
pub fn set_current_error(error: CError)
{
set_errno(error as i32);
set_errno(error.into());
}
/// Clear the current Error.
@ -113,7 +123,22 @@ impl From<i32> for CError
EDOM => { CError::Domain }
ERANGE => { CError::Range }
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::Range => { "Math result not representable" }
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" }
}
}