Fatal Exception – What’s on your call stack?

by gcadmin on Friday, February 23rd, 2018 No Comments

Spead the word -
Twitter
Facebook85K
Instagram107
Follow by Email
RSS

When coding, a Fatal exception is an error or situation that happen while the program is running.  In modular programming, routines often call other routines (Subroutines, procedure, functions, methods etc) to do some work.  Through good design the large complex program is broken into and abstracted into smaller logical components.  This program will often run one routine, which calls another at some stage to do a logical task.  This routine, in turn, may call other routines and functions.    These can also call other routines.

The Stack

Data Stack

Logical Computer Stack

The program stores information that allows it to call the ‘routine’ – this information typically includes arguments to the routine and the return point – in a data structure called the stack.  It’s called the ‘stack’ because each time the current routine calls another routine places more data on the ‘stack’ and the data in the ‘stack’ grows taller.  When a routine finishes, it removes its data from the stack and the stack gets smaller.

Importantly if you look at the stack, it’s effectively a list of what your program is doing – a list of the routines, who called what etc.

 

 

 

Exception – What to do?

When a routine runs and an exception occurs, the well coded  program will have an ‘Exception Handler’.  The skilled programmer has placed in the program and routines and code to catch these exceptions.  Handling these exceptions elegantly means the program not only continues, but perhaps finishes what it was trying to do in the first place.

Java Exception

Example Exception Stack Trace

Here is an example I wrote – some code with an error (on purpose).  See the ‘stack’?  The program main, called a routine called ‘sub1‘ which called ‘subsub1‘   Subsub1 had a problem – and the ‘main’ routine caught it,

What’s on your stack and do you have an exception handler?

If you ‘walk the stack’ on the program, you get to each routine, then the main program.  If you keep going further back logically, you might include the Operating System,  and then the Physical computer.

How about you? What is on your stack?

What are you doing right now? Maybe you are on a Bus.

Why are you doing that?  I’m on the Bus to get to work.

OK. Why are you going to work today?  If I don’t go to work they won’t pay me or might fire me.

OK.  Why is that important? Why do you need the Job?  I need money to pay my bills, rent, buy food.

Great.  Why are you doing that?  My family needs those things – so they have a place to live and grow.

OK. Good. Now why are you doing that?  and so on…

A key point – did you notice you HAVE a call stack?  A list of nested tasks and routines you are doing.

At some point, you are going to run out of answers (quick ones anyway).  It might have been 3 levels, 5 levels or 10 levels.  What ever the number of questions, now you have unwound your stack you are at an interesting place!

Call it the meta-physical level, meditating or staring at your navel.

This is important – what is your exception handler? What do you have that will help you continue if something serious and unexpected occurs to you right now somewhere within your stack of tasks and routines.

The consequence for a program without good exception handling is the program dies – is incomplete. However it was just a program.

Think about your exception handler – you are more important than a program.

Your exception handlers.

In programming, any coder worth their salt will have carefully crafted a series of exception and error Exceptionhandlers through their code.  The key purpose of these is to enable to main program to continue, perhaps in a limited way, but never the less continue its operation.

So as a person, you should have some well crafted   exception handlers.  These could include a job, usually a long term stable partner (wife/husband/life long partner), something meaningful outside of work, maybe kids, maybe a circle of trusted friends, maybe a belief in something important or something bigger than you.

 

The idea is that if or when you have a major  exception in your life, you are able to handle it and continue.  Also having the set of handlers, rather than just a one handler, is that in the event is one of the corner stones of your life has a major exception, you have other parts to help. You survive.  Your partner survives.  Your family survives.

 

For myself, having some belief in something greater, provides the outer most exception handling block.

try {

   my_life.run();  <-- me!

} catch (Exception life_exception)  {

   God.handle(life_exception);  <-- Someone to catch you when you fall.

}


Praying to God

Walk your stack – check what exception handlers you have.  If you don’t have enough exception handlers (or any), then you have something you need to do.

 

Related: DM to God

 

 

 


Posted in Computer Technical, Programming.




Leave a Reply

Your email address will not be published. Required fields are marked *

close

Help spread the word. #Gratitude #Gravitas :)