Navigation and Ancillary Information Facility NIF Exception Handling October 2014.

Slides:



Advertisements
Similar presentations
Chapter 3 Basic Input/Output
Advertisements

Exception Handling. Background In a perfect world, users would never enter data in the wrong form, files they choose to open would always exist, and code.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
Objectives In this chapter you will: Learn what an exception is Learn how to handle exceptions within a program See how a try / catch block is used to.
 Both System.out and System.err are streams—a sequence of bytes.  System.out (the standard output stream) displays output  System.err (the standard.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Jerry Lebowitz. Topics  Provides a facility for a systematic object oriented approach to handling runtime errors ◦ Can also handle runtime errors.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
Finding and Debugging Errors
Basic Input/Output Operations
Exceptions Objectives At the conclusion of this lesson, students should be able to Explain the need for exceptions Correctly write programs that use.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Navigation and Ancillary Information Facility NIF Matlab Interface to CSPICE “Mice” How to Access the CSPICE library Using Matlab © November 2014 © The.
Navigation and Ancillary Information Facility NIF Getting and Installing the SPICE Toolkit October 2014.
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
Object Oriented Programming
Chapter 12: Exception Handling
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
Navigation and Ancillary Information Facility NIF MATLAB Interface to CSPICE “Mice” How to Access the CSPICE library Using MATLAB © October 2007 © The.
MICROPROCESSOR INPUT/OUTPUT
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
PHP Workshop ‹#› PHP Error Handling. PHP Workshop ‹#› Types There are 12 unique error types, which can be grouped into 3 main categories: Informational.
Errors And How to Handle Them. GIGO There is a saying in computer science: “Garbage in, garbage out.” Is this true, or is it just an excuse for bad programming?
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
Introduction to Exception Handling and Defensive Programming.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Exceptions in Java. Exceptions An exception is an object describing an unusual or erroneous situation Exceptions are thrown by a program, and may be caught.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Navigation and Ancillary Information Facility NIF IDL Interface to CSPICE “Icy” How to Access the CSPICE library Using Interactive Data Language (IDL)
Navigation and Ancillary Information Facility NIF IDL Interface to CSPICE “Icy” How to Access the CSPICE library Using Interactive Data Language (IDL)
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Navigation and Ancillary Information Facility NIF Exception Handling November 2014.
Navigation and Ancillary Information Facility NIF IDL Interface to CSPICE “Icy” How to Access the CSPICE library Using Interactive Data Language (IDL)
Navigation and Ancillary Information Facility NIF IDL Interface to CSPICE “Icy” How to Access the CSPICE library from the Interactive Data Language (IDL)
Navigation and Ancillary Information Facility NIF Porting Kernels November 2005.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
Exceptions, handling exceptions & message boxes Year 11 Information Technology.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Navigation and Ancillary Information Facility NIF Using Module Headers April 2006.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Sequencers SQO,SQC,SQL.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Navigation and Ancillary Information Facility NIF Getting and Installing the SPICE Toolkit November 2014.
Introduction to Exceptions in Java CS201, SW Development Methods.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Eighth Lecture Exception Handling in Java
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
IDL Interface to CSPICE “Icy”
Scripts & Functions Scripts and functions are contained in .m-files
Topics Introduction to File Input and Output
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Topics Introduction to File Input and Output
Presentation transcript:

Navigation and Ancillary Information Facility NIF Exception Handling October 2014

Navigation and Ancillary Information Facility NIF Exception Handling 2 What Exceptions Are Language Dependencies C and Fortran Error Handling Features Error Messages Error Handling Actions Error Device Customize Error Handling Get Error Status Signal Errors Icy Error Handling Mice Error Handling Recommendations Topics

Navigation and Ancillary Information Facility NIF Exception Handling 3 Run time error conditions –Files »Required files not loaded. »Gaps in data. »Corrupted or malformed files (e.g. ftp’d in wrong mode). –Invalid subroutine/function arguments »String values unrecognized. »Numeric values out of range. »Data type/dimension mismatch. –Arithmetic errors »Divide by zero, square root of a negative number. –Environment problems »Insufficient disk space for output files. »Lack of required read/write permission/privileges. Exceptions Are… - 1

Navigation and Ancillary Information Facility NIF Exception Handling 4 Valid but unusual conditions –Examples are: »Normalize the zero vector. »Find the rotation axis of the identity matrix. »Find the boresight intercept lat/lon for a non-intercept case. »Find a substring where the end index precedes the start index. –Such cases are normally not SPICE “Error Conditions” –Typically must be handled by a logical branch Errors found by analysis tools, such as parsers –Examples are: »Invalid SQL query. »Invalid string representing number (borderline case). –Such cases are normally not SPICE “Error Conditions” –However, if a SPICE parsing routine failed because it couldn’t open a scratch file, THAT would be an “error condition.” Exceptions Are… - 2

Navigation and Ancillary Information Facility NIF Exception Handling 5 Language Dependencies SPICELIB and CSPICE provide essentially identical error handling capabilities. Icy and Mice provide similar error handling functionality; this functionality is quite different from that of CSPICE. –These systems do rely on CSPICE for most error detection. –Icy and Mice provide no API for customizing underlying CSPICE error handling behavior. –Short, long, and traceback error messages are merged into a single, parsable, message. –Use IDL or MATLAB features to customize error handling… »to prevent your program from stopping »to capture SPICE error messages Most of this tutorial deals with SPICELIB and CSPICE error handling. –There is a bit on Icy and Mice near the end.

Navigation and Ancillary Information Facility NIF Exception Handling 6 Error handling in SPICE: safety first –Trap errors where they occur; don’t let them propagate »Don’t let errors “fall through” to the operating system. –Supply meaningful diagnostic messages »Incorporate relevant run-time data. »Supply context in human-readable form. –Don’t depend on callers to handle errors »Normally, “error flags” are not returned to callers. –Stop unless told not to »Don’t try to continue by making “smart guesses.” Subroutine interface for error handling –Interface routines called within SPICE may be called by users’ application programs Fortran and C Error Handling Features - 1

Navigation and Ancillary Information Facility NIF Exception Handling 7 Signal errors –Create descriptive messages when and where an error is detected »Short message, long message, (explanation), traceback –“Signal” the error: set error status, output messages »By default, CSPICE error output goes to stdout (not stderr) Retrieve error information –Get status and error messages via subroutine calls Customize error response---actions taken when an error occurs. –Set error handling mode (“action”) –Set error output device –Set message selection Inhibit tracing –To improve run-time performance (only for thoroughly debugged code) Fortran and C Error Handling Features - 2

Navigation and Ancillary Information Facility NIF Exception Handling 8 Short message –Up to 25 characters. –Can easily be compared with expected value. »Example: SPICE(FILEOPENFAILED). Long message –Up to 1840 characters. –Can contain values supplied at run time. »Example: 'The file was not found.' Traceback –Shows call tree above routine where error was signaled. »Not dependent on system tracing capability. »Don’t need a “crash” to obtain a traceback. Error Messages

Navigation and Ancillary Information Facility NIF Exception Handling 9 ABORT –Designed for safety. »Output messages and traceback to your screen or stdout. »Stop program; return status code if possible. RETURN –For use in programs that must keep running. –Attempts to return control to the calling application. –Preserves error information so calling application can respond. »Output messages to current error device. »Set error status to “true”: FAILED() will return “true.” »Set “return” status to “true”: RETURN() will return “true.” »Most SPICE routines will return on entry. Very simple routines will generally execute anyway. Error Handling Actions continues--

Navigation and Ancillary Information Facility NIF Exception Handling 10 »Capture traceback at point where error was signaled. »Inhibit error message writing and error signaling. »Must call RESET to resume normal error handling. Error Handling Actions - 2

Navigation and Ancillary Information Facility NIF Exception Handling 11 Destination of error messages –Screen/stdout (default) –Designated file »Error diagnostics are appended to the file as errors are encountered. –“NULL” --- suppress output »When the NULL device is specified, error messages can still be retrieved using API calls. Limitations –In C, cannot send messages to stderr. –In C, writing to a file opened by means other than calling errdev_c is possible only if CSPICE routines were used to open the file. »These limitations may be removed in a later version of CSPICE. Error Device

Navigation and Ancillary Information Facility NIF Exception Handling 12 Set error action –CALL ERRACT ( ‘SET’, ‘RETURN’ ) –erract_c ( “set”, LEN, “return” ); »Length argument is ignored when action is “set”; when action is “get”, LEN should be set to the available room in the output string, for example: »erract_c ( “get”, ACTLEN, action ); Set error device –CALL ERRDEV ( ‘SET’, ‘errlog.txt’ ) –errdev_c ( “set”, LEN, “errlog.txt” ); Select error messages –CALL ERRPRT ( ‘SET’, ‘NONE, SHORT, TRACEBACK’ ) »If tracing is disabled, selecting TRACEBACK has no effect. –errprt_c ( “set”, LEN, “none, short, traceback” ); Customize Error Handling - 1

Navigation and Ancillary Information Facility NIF Exception Handling 13 Disable tracing –Normally done to speed up execution by a few percent –Benefit is highly dependent on application –NAIF normally recommends users not turn tracing off –Use TRCOFF: »CALL TRCOFF or trcoff_c(); Do this at the beginning of your program. Once disabled you cannot re-enable tracing during a program run. Customize Error Handling - 2

Navigation and Ancillary Information Facility NIF Exception Handling 14 Use FAILED to determine whether an error has been signaled –IF ( FAILED() ) THEN … –if ( failed_c() ) { … Use FAILED after calling one or more SPICE routines in a sequence –Normally, it’s safe to call a series of SPICE routines without testing FAILED after each call Use GETMSG to retrieve short or long error messages –CALL GETMSG ( ‘SHORT’, SMSG ) –getmsg_c ( “short”, LEN, smsg ); Get Error Status - 1

Navigation and Ancillary Information Facility NIF Exception Handling 15 Use QCKTRC or TRCDEP and TRCNAM to retrieve traceback message Test value of RETURN() to determine whether routines should return on entry –Only relevant if user code is designed to support RETURN mode Handle error condition, then reset error status: –CALL RESET –reset_c(); –In Icy-based applications you only handle error condition; a reset is automatically performed by Icy Get Error Status - 2

Navigation and Ancillary Information Facility NIF Exception Handling 16 Create long error message –Up to 1840 characters –Use SETMSG »CALL SETMSG ( ‘File was not found.’ ) »setmsg_c ( “File was not found.” ); Substitute string, integer, or d.p values at run time –Use ERRCH »CALL ERRCH ( ‘#’, ‘cassini.bsp’ ) »errch_c ( “#”, “cassini.bsp” ); –Also can use ERRINT, ERRDP –In Fortran, can refer to files by logical unit numbers: ERRFNM Signal Errors - 1

Navigation and Ancillary Information Facility NIF Exception Handling 17 Signal error –Use SIGERR to signal error. Supply short error message as input to SIGERR. »CALL SIGERR ( ‘FILE OPEN FAILED’ ) »sigerr_c ( “FILE OPEN FAILED” ); –“Signaling” error causes SPICE error response to occur »Output messages, if enabled »Set error status »Set return status, if error action is RETURN »Inhibit further error signaling if in RETURN mode »Stop program if in abort mode Reset error status after handling error –CALL RESET() –reset_c() Signal Errors - 2

Navigation and Ancillary Information Facility NIF Exception Handling 18 Error action: –By default, a SPICE error signal stops execution of IDL scripts; a SPICE error message is displayed; control returns to the execution level (normally the command prompt). –Icy sets the CSPICE shared object library’s error handling system to RETURN mode. No other modes are used. »The CSPICE error state is reset after detecting an error. –Use the IDL CATCH feature to respond to error condition. Error status –Value of !error_state.name »ICY_M_BAD_IDL_ARGS - indicates invalid argument list. »ICY_M_SPICE_ERROR - indicates occurrence of a SPICE error. Error message –CSPICE short, long, and traceback error messages are merged into a single, parsable, message. »The merged error message is contained in the variable !error_state.msg. »Example: CSPICE_ET2UTC: SPICE(MISSINGTIMEINFO): [et2utc->ET2UTC->UNITIM] The following, needed to convert between the uniform time scales, could not be found in the kernel pool: DELTET/DELTA_T_A, DELTET/K, DELTET/EB, DELTET/M. Your program may have failed to load… Icy Error Handling

Navigation and Ancillary Information Facility NIF Exception Handling 19 Error action –By default, a SPICE error signal stops execution of MATLAB scripts; a SPICE error message is displayed; control returns to the execution level. –Mice sets the CSPICE shared object library’s error handling system to RETURN mode. No other modes are used. »The CSPICE error state is reset after detecting an error. –Use the MATLAB try/catch construct to respond to error condition. Error message –CSPICE short, long, and traceback error messages are merged into a single, parsable, message. »Example: ??? SPICE(MISSINGTIMEINFO): [et2utc->ET2UTC->UNITIM] The following, needed to convert between the uniform time scales, could not be found in the kernel pool: DELTET/DELTA_T_A, DELTET/K, DELTET/EB, DELTET/M. Your program may have failed to load… Use the MATLAB function lasterror to retrieve SPICE error diagnostics. When a SPICE error occurs: –the “message” field of the structure returned by lasterror contains the SPICE error message. –the “stack” field of this structure refers to the location in the m-file from which the Mice wrapper was called (and so is generally not useful). –the “identifier” field of this structure currently is not set. Mice Error Handling

Navigation and Ancillary Information Facility NIF Exception Handling 20 For easier problem solving –Leave tracing enabled when debugging. –Always test FAILED after a sequence of one or more consecutive calls to SPICE routines. –Don’t throw away error output. It may be the only useful clue as to what’s going wrong. »Programs that must suppress SPICE error output should trap it and provide a means for retrieving it. Test FAILED to see whether an error occurred. Use GETMSG to retrieve error messages Use RESET to clear the error condition –Use SPICE error handling in your own code where appropriate. –When reporting errors to NAIF, have SPICE error message output available »Note whether error output is actually from SPICE routines, from non-SPICE code, or was generated at the system level. Recommendations