What is open source software


Exception/Error Handling, An Integral Part of Programming

Exception handling is an essential part ofstates:Exp  No:  4026
the programming experience, it polishes the
application and is a bulwark against somewhatExp Desc: Index out of boundsAn exception
forgivable oversight. We most likely will notnotification needs to provide two types of
cover every situation in the first build ofuseful information, diagnosis information for
an application but at least we can includethe developer or the vendor of the
the ability to handle unforeseen runtimeapplication and explanatory information for
exceptions and build some useful toolsthe end user or the the vendor's client.
utilising exception systems to help with theUseful details to provide can be:Routine
application development process.CUSTOMname. The name of the routine in which the
EXCEPTIONSexception  occurred.
=================Custom built exceptions areLine number. If available the code line
a handy tool for both release and developmentnumber or last declared line number when the
versions of an application. They can be usedexception occurred. This can really help pin
in the following ways:Custom Exceptions aspoint the line of code the exception occurred
Developer  Warningswithin.
---------------------------------------WeClass or module name. This helps locate the
can use exceptions to remind us of notcode  that  threw  the  exception.
providing requisite information to a class or
object. For example: We build a class as anCall stack: This can be useful to trace the
interface to multiple vendor databases, let'sseries  of  events  prior  to  the exception.
call it Multiple Vendor Management (MVM)
class. To connect to a particular database weActive controls or forms: The current active
perforce provide the instantiated MVM classcontrol and/or form which could give a clue
with the vendor database type we areas to what the user was trying to do when the
connecting to via a database_type methodexception occurred, although the call stack
within the class. The MVM class also has acould  cover  this  instead.
SQL_select method that can be called to
return a recordset from our chosen vendorSource of the exception: Perhaps the
database. Within the SQL_select method is aexception was caused by an application
switch (select case) statement which decidesinteractivity  or  interoperability.
how to send the 'select request' to our
chosen database type. If we fail to provideTime of the exception: Maybe the user went
the vendor database type to our class andto lunch before reporting the exception. It
call the SQL_select method at runtime or amay help to know that when the exception
debug compilation, a default (case else)occurred there was a concurrent hiatus of
option within our switch (select case)intranet  connectivity.
statement throws a custom exception for
developers. The custom exception will remindUser explanation: An explanation for the
a developer during runtime testing that theuser on how the exception impacts their
requirements of the class have not beenability to carry out their tasks. It probably
fulfilled during our coding. Below is anis not necessary to confuse the user with
example of where our custom exception can beexactly what went wrong, just that the
used:Private Sub SQL_select(SQL As String)dimapplication can not perform their task at the
exp_developer_1  as  RuntimeExceptionpresent  time.HANDLING  HIDDEN  ASSUMPTIONS
exp_developer_1  =  new  RuntimeException===========================As a rule I put
exception handling into almost every routine
exp_developer_1.Message = "'database_type'to neutralise the spectre of the hidden
property  is  not  set."assumption. I am currently working with a
business process diagramming application in
exp_developer_1.ErrorNumber = -90000dim rswhich there are scripted reports. One
As RecordSetselect case database_typecaseparticularly critical report every now and
MySQL_DATABASEthen can not complete it's processing, this
is a legacy report which has code that makes
if  Connect_mysql  theninadequate use of exception handling. Every
time the report stops I diagnose the problem
rs  =  mysql.SQLSelect(SQL)as missing Lane symbol names within the
diagram the report is trying to process. The
end  if  //  Connect_mysqlcase ODBC_DATABASEdeveloper who had scripted the report
mistakenly assumed that there would always be
if  Connect_odbc  thena name attributed to a Lane symbol, but when
a user forgets to enter a Lane symbol's name,
rs  =  odbcdb.SQLSelect(SQL)the report stalls and has no way to handle
the exception that is thrown. The hidden
end  if  //  Connect_odbccase  REAL_DATABASEassumption is: A Lane symbol has a name
property therefore there is a name value
if  connect_rbdb  thenavailable within that property. Of course the
developer and client most likely tested the
// replace any instance of the word DISTINCTreport against well formed diagrams before
with  UNIQUE  to  cater  for  RBDB  syntax.releasing the first build so the exception
was never thrown during testing. This is not
SQL =really any party's fault but the result of
Replace_passed_regex_strings(SQL,"sDISTINCTs"human fallibility that has not been catered
,"  UNIQUE  ")for by utilising exception handling.EXCEPTION
LISTENER
rs  =  rbdb.SQLSelect(SQL)
==================Instead of building a
end  if  //  Connect_rbdbcase  elsecentral exception handler to provide
exception notification or central exception
Raise exp_developer_1end selectExceptionreporting we could create an class that
errd=New  MessageDialogcaptures exceptions and performs functions
based upon the type of exceptions it
if  err  =  exp_developer_1  thenreceives. One function might be to capture
exceptions into a collection and provide
d.Set_Icon_Caution_Triangleadvice to calling routines as to what kinds
of services the application can provide the
elseuser at any one time, for example: We have an
application that accesses several diverse
d.Set_Icon_Stopdata sources which upon start up fails to
connect to one of it's data sources and
end ifd.ActionButton.Caption = "OK"#ifthrows an exception. The exception is handled
TargetWin32  or  TargetLinux  Thenand passed to the Exception Listener. From
now on any event that opens a form can call
//ERR_MODULE is a constant that holds thethe Exception Listener to see if any details
module's/form's  name  +  a  full  stopthe form provides the user are inaccessible
and as a result can disable controls that
d.Title = ERR_MODULE + "SQL_select"if err =allow the editing or reading of those
exp_db_error  thendetails. The latter scenario would allow the
user to still perform some duties although in
d.Message = d.ERROR_NUMBER_TEXT +a limited way, which is better than not
cstr(exp_db_error.ErrorNumber)  + _allowing the user to do any work and may
still enable the user to finish their work
EndOfLine + d.ERROR_DESCRIPTION_TEXT +tasks with the limited functionality
exp_db_error.Message  'messageprovided. When I say limited functionality we
could be speaking of only a minor disruption
elsed.Message = d.ERROR_NUMBER_TEXT +to functionality overall.Another benefit of
cstr(err.ErrorNumber)  + _an Exception Listener could be the ability to
periodically check the collection of
EndOfLine + d.ERROR_DESCRIPTION_TEXT +exceptions it holds and try to resolve the
err.message  'messageoriginal cause of the exceptions. In the
example above where our application could not
end  ifaccess a data source, the Exception Listener
could thread a retry of the connection whilst
#else//ERR_MODULE is a constant that holdsthe application is running and upon a
the  module's/form's  name  +  a  full  stopsuccessful connection notify it's clients of
the availability of details from the data
d.Message = d.ERROR_ROUTINE_TEXT +source again and remove the exception from
ERR_MODULE  +  "SQL_select"  +  EndOfLinethe collection. This is better than the user
having to save what they are doing, close the
if  err  =  exp_db_error  thenapplication and reopen it to reconnect to a
previously inaccessible data source.If our
d.Message = d.Message + d.ERROR_NUMBER_TEXTException Listener was a software bus it
+  cstr(exp_db_error.ErrorNumber)  + _could publish any messages to it's
subscribers within the application and we
EndOfLine + d.ERROR_DESCRIPTION_TEXT +could have a real-time release of limited
exp_db_error.message  'messagefunctionality within forms, web pages and
other interfaces.Statistical Analysis of
elsed.Message = d.Message +Application  Functionality
d.ERROR_NUMBER_TEXT + cstr(err.ErrorNumber) +
_
---------------------------------------------
EndOfLine + d.ERROR_DESCRIPTION_TEXT +----Statistical analysis of the amount of
err.message  'messagefunctionality that can be provided by an
application can also be published by the
end  ifException Listener where a missing data
source may be determined to reduce the
#endifd.AlternateActionButton.Caption =application's functionality by 25%. The user
"Details  to  Clipboard"can be notified that the application is only
75% functional which would be useful
d.AlternateActionButton.Visible  =  Trueinformation in a unstable environment. The
percentage of functionality would rise or
b=d.ShowModalSelect  case  bfall based upon exception resolution and
exceptions thrown respectively.Exception
case  d.ActionButtonCluster  Explanation
case  d.AlternateActionButton-----------------------------With a
collection of exceptions within the Exception
d.Details_to_clipboardcase  d.CancelButtonListener we could abstract out a
comprehensive explanation of what an
end  selectfinallyapplication's current capabilities and
limitations are by diagnosing clusters of
//  clean  upvarious exceptions and/or exception types.
When a user tries to perform a task and
if  dNil  then  d=Nilreceives an exception the notification of the
exception could provide the ability to open
return  rsan explanation dialogue instead of only
providing the ability to dismiss the
End SubCustom Exceptions used for Call Stackexception notification. The Exception
RetrocessionListener could provide a comprehensive report
upon current application limitations that are
producing current system behaviour. For
---------------------------------------------example, even though our application may have
-----A custom exception could be used tosuccessfully connected to an Account system
create a call stack ( break out scenario. Forwe cannot retrieve a staff member's salary
example, we have an application that is sixtransactions because our application cannot
calls down a call stack of databaseaccess the necessary employee identification
transaction routines and a critical datadetails on a Human Resources system that is
error has occurred. Instead of handling theoffline. Throwing an exception that informs
exception, exiting the routine and allowingthe user that an accounts routine can not
the parent routine to continue processingperform its task does not explain why this
it's database transactions we use a customhas happened and the user will most likely
exception to roll back all calls within thecontact the help desk for the explanation,
call stack and their transactions. We throwwhereas a comprehensive explanation from the
the custom exception within the currentException Listener which explains the effects
routine whose exception handler rolls backof a Human Resources system being offline
our current routine's database transactionscould instantly explain why the accounts
and then throws the custom exception againroutine  is  failing  the  user.SUMMARY
within the exception handling section of our
routine's code. The exception handler in our=======Exception handling is an integral and
current routine cannot handle the newlysometimes unappreciated part of any
thrown custom exception so transfers controlprogramming regimen. Points covered
back up the call stack to the previouswere:Custom exceptions help with the
routine. The previous routine handles thedevelopment process using custom developer
custom exception in the same way, and so onexceptions to remind developers of missed
until we reach the top of the stack, havingrequirements  during  coding.
rolled back all routines' database
transactions. The initiating routine of theCustom exceptions can retrocede through a
stack can then report the exception or, thecall stack and rollback prior transactions
routine that caught the first exception couldand  processes.
report the exception (see heading Exception
Notification Detail further on in article forExceptions can handle the scripting of our
why we would do this) and then start thehidden  assumptions.
retrocession of the stack.Custom Exception
GenericsException Listeners can provide the ability
to limit services within an application
--------------------------Custom exceptionsallowing the user to perform tasks albeit
do not need to be specific in their reportingsome  functionality  will  be  disabled.
detail, they are custom built so we can
change their messages to better fit theException Listeners can provide
circumstance in which we want to throw thecomprehensive explanations of limited
exception. For instance, say we have a customapplication behaviour and the possible cause
database exception:dim exp_db_error asof  thrown  exceptions.
RuntimeException
Exception Listeners can provide a
exp_db_error.number  =  -10001statistical percentage of application
functionality.
exp_db_error.message = "Database file can
not be found."We raise this exception withinException Listeners can periodically try to
a routine where the database file is foundresolve earlier exceptions that reduce a
but is corrupt, we can change the message tosystem's  functionality.
better fit the circumstance of the
exception:exp_db_error.message = "DatabaseException notifications can provide enough
file  is  corrupt."detail for a developer or vendor to pinpoint
the cause of an exception in code whilst
Raise exp_db_errorThe exception numberconcurrently providing a useful explanation
relates to database specific issues but theto assuage user anxiety over an
message the user receives is more relevant toexception.Duane  Hennessy
the situation than a generic exception
message.EXCEPTION  NOTIFICATION  DETAILSenior Software Engineer and Systems
Architect
=============================Details
provided in exception notifications perforceBandicoot  Software
should be useful to both the developer and
the end user. A basic exception-type numberTropical  Queensland,  Australia
and description is usually too vague or
concise to be of use to either party. What(ABN: 33 682 969 957)Your own personal
good is an exception notification thatlibrary of code snippets.



1 A B C 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86