Crate nes [] [src]

NES - New Error System is the library for rust, that makes the syntax more elegant for operating by errors. Each error stores the location in source code, where the error has been occurred, because some errors like std::io::Error may occurs in different places in code, so it is useful for detection of problems. Note, that this errors are useful for users or sysadmins. panic!() is preferable for developers to detect bugs. For example, server can not be started because port 80 is busy. In this case you should show user the window, that contains simple information and print to log more detailed information.

You can match errors:

# Example

#![feature(box_patterns)]

match process() {
    Ok(_) => {},
    Err(CommonError::IncorrectExtension(_,file_name, extension)) => println!("incorrect extension {}",extension),
    Err(e) => {
        match e {
            //_, is error_info that contains information, where the error has been occurred, we skip it
            CommonError::ReadFileError(_, box ReadFileError::ReadFileError(_,ref io_error, ref file)) => println!("can not read file \"{}\"",file),
            _ => {println!("{}",e)} //or println!("{:?}",e)
        }
    }
}

By println!("{}",e) You will get error like(not in case above):

example/examples/example.rs 16:0   //line, where impl_from_error!() is.
read file error example/examples/example.rs 51:13    //line where thr error has been occurred
Can not read file "no_file.rs" : No such file or directory (os error 2)    //description of error

Do not forget to see examples directory

Macros

channel_send

This macro sends a message into channel and returns error if channel is brocken(second thread has panicked or finished).

create_err

This macro creates error that gets information, where the error has been occurred. You can insert it into other error.

define_error

This macro defines the error.

err

This macro generates error that gets information, where the error has been occurred. You should return it.

error_info

This macro returns file,line,column, where an error has been occurred

impl_from_error

This macro implements From trait for other errors.

mutex_lock

This macro helps to lock mutex and returns error if it is poisoned(second thread has locked the Mutex and panicked).

ok

This macro makes a syntax more beautiful.

result

This macro avoids overabundance of <<>> and makes a syntax more beautiful.

rw_read

This macro helps to lock rw_lock(calls read) and returns error if it is poisoned(second thread has locked the RwLock and panicked).

rw_write

This macro helps to lock rw_lock(calls write) and returns error if it is poisoned(second thread has locked the RwLock and panicked).

try

This macro looks like standard try!() macro but it gets information where the error has been occurred.

Structs

ErrorInfo

This is standard ErrorInfo structure.

Traits

ErrorInfoTrait

You should implement this trait for your own ErrorInfo, then you need, for example, get current time and write to log in method new.