ColdFusion : Error Handling – Part 1

NOTIFICATION: These examples are provided for educational purposes. Using this code is under your own responsibility and risk. The code is given ‘as is’. I do not take responsibilities of how they are used.

Errors are unforseen. They are a result produced by coding and they are unplanned and/or unanticipated by the developer.
However, we can manage these errors and used them to our advantage.

Errors are handle by the server is the following fashion:

  1. The first level are the system errors.
    System error are generated when some components are not working properly.
    For example, if your application requires access to a database and this database is at a server which is down, then this could generate your application to fail.
  2. The second level are the code level errors. These errors (or exceptions) include logic, syntax and other type of errors that we will see later
  3. The third level of errors are at the application level
  4. The last level of errors are at the server level.

Error Flow Diagram:

Figure 1
Figure 1

As you may notice from the figure 1, we have a classification for all the errors that can be generated:

  1. Logic: These kind of errors are generated from some fault in the design of the code.
    For example, you could have an infinite loop:

    <CFSET counter = 0>
    <CFLOOP CONDITION='counter GTE 10'>
            Counter: #counter# <BR/>

    This loop will work while the counter is not greater or equal (GTE) to 10.
    The problem is that there is no part of this code that increases the counter.
    Since the variable counter is always 0, the loop is considerate infinite and can affect the server

  2. Syntax: These errors are related with misspelling, invalid data types, invalid parameters, and everything related with the language syntax. This kind of errors are caught on the application server and server level.
    For example:

    <CFOUTPUT QUERY='yourQuery'>
        <CFOUTPUT>Count of Records: #yourQuery.recordCount# <BR/></CFOUTPUT>
        <CFOUTPUT>#yourQuery.nonExistentField# <BR/></CFOUTPUT>

    The second like is going to work; however, the third line is asking for a field that doesn’t exist in myQuery structure.
    Another Example:

    <CFOUTPUT QUERY='yourQuery'>
        <CFOUTPUT>Count of Records: #yourQuery.recordCount# <BR/><CFOUTPUT>

    Here you are forgetting to close both CFOUTPUTs.

  3. Runtime: These are unforseen conditions such as data type mismatches, out of scope issues, server-side form validation errors, etc.
    For example:

    <CFPARAM NAME='user_age' default='My name is Alejandro'>
    <CFPARAM NAME='legal_driving_age' default=21>
    <CFIF Int(user_age) GT legal_driving_age>
        <CFOUTPUT>This user can apply for a regular driving licence</CFOUTPUT>
        <CFOUTPUT>This user cannot apply for a regular driving licence.</CFOUTPUT>

    This example fail on: <CFIF Int(user_age) GT legal_driving_age>
    Because user_age is a string without numbers while the function Int() is expecting a string with number.
    Since Int() cannot convert the string, a runtime error will be generated.

    There are three way to caught these exceptions which we would see later:

    1. Via code-level
    2. Via application-level
    3. Via server-level
  4. Validation: We can see validation errors as of the runtime errors that we are going to have to deal with.
    This kind of erros happens when Coldfusion server-side form catches a problem with the submitted data.

    <FORM ACTION='process.cfm' METHOD='POST'>
        <INPUT TYPE='text' NAME='age_integer' value='only text, no integers here'>
        <INPUT TYPE='submit' value='Submit' />

    You may ask: where is the error here?
    Well, in coldfusion we can do integer validation of the input by adding “_integer” to the name of the input field.
    In this case, “age_integer” means that we have a input name “age” which should be validated for integers.
    Since the value is “only text, no integers here” which is pure string, this will fail the validation. 
    For more information you can go to the following link:

    Lets clarify that these kind of errors can only be caught via error handlers at the aplication-level.

  5. System: Errors related with the system are always about inaccessible databases, unavailable resources, incorrect or invalidly configured servers, and file system errors such as lack of permissions.
    For example:

    <CFINCLUDE TEMPLATE='non_existent_file.cfm'>

    These errors can be caught:

    1. Via code-level handlers
    2. Via applicatoin-level handlers
    3. Via server-level handlers
  6.  Request: These errors occurs when the client request for invalid resources not available from the server side.
    Example:Such errors can be caught via server-wide error handlers.

Notes: Operative Systems – Part 1

(Operative Systems – Part 2) Next >

NOTIFICATION: These notes are published for educational purposes. Using these notes is under your own responsibility and risk. These notes are given ‘as is’. I do not take responsibilities for how you use them.

PDF Content:

  • Software and Hardware structure
  • Application Binary Interface (ABI)
  • Application Programming Interface (API)
  • Memory hierarchy
  • Hard drives
  • Interrupt processing
  • What is an Operating System (OS)
  • CPU privilege levels
  • Process
  • Memory layout of a typical process
  • Multiple processes sharing main memory
  • Process creation
  • Process hierarchy tree
  • Exec(), wait(), fork(), waitpid(), sleep(), and exit() functions
  • Orphan process
  • Zombie process
  • Possible process states
  • Kernel-level data structure
  • Process management
  • Memory management
  • File management
  • System call
  • Inter-process Communication (IPC)
  • Semaphores, signals, shared memory, sockets, pipes
  • Parent-child communication using pipes
  • read() and write() functions
  • Error handling
  • Handling signals
  • SigChild
  • CPU scheduling
  • Process life-cycle
  • CPU-bound process
  • I/O-bound process



(Operative Systems – Part 2) Next >


Introduction to Network Security – Part 2

NOTIFICATION: These examples are provided for educational purposes. The use of this code and/or information is under your own responsibility and risk. The information and/or code is given ‘as is’. I do not take responsibilities of how they are used.

Introduction To Network : The Internet

The Internet is a network which connect networks around the world. Each end system (normally end users computers) obtain access thought an Internet Service Provider (ISPs).


A protocol is a way in which rules for communication are established. For example, in a court, there is a procedure and language that must be follow in the process. A network protocol will define a language of rules, format, order of messages, entities, actions to take, and convention in order to the message being transmitted.

For example: A user which to see a website, therefore the browser will make a TCP request to the server. Due the TCP request form the client, the server answer with a TCP response to the client. Then the client perform a request for the page to the server. Finally, the server send the page requested by the client.

Protocol Layers

A protocol divided the components needed for transition of messages in modular layers (modulation of the components helps to maintain, update, and/or perform changes to the component). The implementation of layers must be done in the way that it is transparent to the rest of the system as will be explained later. The following image provide an example of the actual layers used for the TCP/IP protocol and the protocol layers recommended by the OSI model.

As you can witness, in the actual TCP/IP protocol, we have five well defined layers.

This layers are:

  1. Application Layer: This layers permit the user to access the information that is being send and/or receive from the network through the application in used for this purpose.
    1. This layer support application-layer protocols such as Hyper-Text Transfer Protocol (HTTP), File Transfer Protocol (FTP), Secure  SHell (SSH), and others.
    2. The information to be transmitted is send over the application layers which is in charge to encapsulate the data into the application layer protocol and transfer the encapsulated data to the transport layer.
  2. Transport Layer: This layer is in charge to provide to end users a transparent transfer of data.
    1. This layer provide controls of reliability of a given link through flow control segmentation/de-segmentation plus error control.
    2. The most common segments used today are Transmission Control Protocol (TCP) and User Datagram Protocol.
      1. Transmission Control Protocol (TCP) is know to be a reliable connector-oriented protocol. Commonly used to send data.
      2. User Datagram Protocol  (UDP) is know to be a faster but unreliable connector-oriented protocol. Commonly used for streaming media such as radio, movies, clips, and TV online.
  3. Network Layer: This layer is in charge of routing the datagrams from the source to the destination using routing protocols such as Internet Protocol (IP). All routes operate at this layer.
  4. Link Layer: This layer is used for the transfer of data between network entities such as bridges and switches by providing the functional and procedural means.
  5. Physical Layer: All the data is encoded and transmit as raw data over the network media by making sure that the information that is send in one side is received at the other side accurately.