c++ - trouble with error function -


Currently the principles of programming and principles using C ++ and I am not quite able to understand how the error function is used as it was used. in the book.

is the function

  inline zero error (constring & amp;;); Runtime_error (s); }   

which was included in the std_lib_facilities header file.

This is a small program that uses it.

  int main) {Cout & lt; & Lt; "Please enter the expression (we can handle +, one, ???, *, and /) \ n"; Cout & lt; & Lt; Add an X to the end expression (i.e., 1 + 2 * 3x): "; IntraLval = 0; Interview; Cin & gt; & Gt; Lval; Read one / one read / left most operation and Read (if! Cin) error ("any first operand"); For one (one- Â € œCinâ € | rival; if (! Cin) error ("any other operand"); switch (op) {case '+': Level = = Raval; One / One / One plus: Laval = Rawal = Rawal Break; Case 'One' '' '' '' '' '' '' One '' / decrease: One = one '' Rval break; Case '*': Levell * = Raval; One / One Multiplication: Target = Laval * Rawal Break; Case '/': Laval / = Raval; One / One Default: Lv = Raval / Raval Break; Default: Not another operator: Another operator: Print result cout & lt; & lt; "Result:" & lt; & lt; Rev. & lt; & lt; '\ N' ; Keep_window_open (); return 0;}} error ("bad expression");}   

My question is, how does this error function work if caught for catching an error To throw it away so that your message can be displayed.

to Make sure Not that error message is printed, when the quality of implementation need to be yourself.

Like,

  #include & lt; Iostream & gt; // std :: cout, std :: cerr #include & lt; Stdexcept & gt; // std :: runtime_error #include & lt; Stdlib.h & gt; // EXIT_FAILURE, EXIT_SUCCESS #include & lt; String & gt; // std :: string using namespace std; Auto Fail (String Const & amp;) - & gt; Bowl (fast runtimers); } Void cpp_main () {// Do you keep directly in 'Main', e.g. Cout & lt; & Lt; "X?"; Double X; Cin & gt; & Gt; X || Failed ("oh oh, it was not a valid value for x."); } Auto Main () - & gt; Int {try {cpp_main ()} Return EXIT_SUCCESS; } Hold (exception file & amp; x) {cerr & lt; & Lt; "!" & Lt; & Lt; X.what () & lt; & Lt; Endl; } Return EXIT_FAILURE; }   

Disclaimer: Code is insulated from the hands of composers.


Tip: You can use the free ASTL format to fix the formatting of your code.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -