How to use catch, try and final in bash script

Hi Everyone,

How to use catch, try and final in bash script?
what is (SQLException e) and (IOException e), who to conver this 2 function to bash script?

Thank you

You don't. BASH is not a OO language implementing any features remotely like that.

is it posibble for me to the tranditional logical? coz i just need the logical.. so that i make by my own function instead of OO function...

What do you mean by "traditional logic"? Shell scripts work pretty much like any functional language, a command can either work OK or fail. If the coder has been nice it will give you some information on why it failed. $? is the variable set to the return code of a program, 0 means "good", anything else usually is bad.

Exceptions are done by

  1. Knowing which program you called last (sed probably won't produce and SQL error) and
  2. hoping that the coder used different return codes for different errors, instead of just "good" and "bad"

Thank you pludi and Corona688...

Regarding "tranditional logic, means normal logical... like if else...

I think shell script can do the OO function, just wan to know how its works for the (SQLException e) and (IOException e).

thankx...

no OO support for shell scripts. If you want OO, use a programming language like Python (Java, Ruby, even Perl). you can then use try,catch eg, Python

import os
try :
   os.rename(oldfile,newfile) #try to rename file
except Exception,e:
   print e #print error message
else:
   # do something if pass

Well, if you're really really determined, very very frustration resistant, and have a whole lot of time on your hand, it might be possible to simulate OO in shell scripts.

And again, there are no exceptions in shell scripts, only "good" or "bad" exits

Yes.. i have no choice.. Boss ask me to convert WEBLOGIC to CGI...
so, everything must simulate like java...
i don know how....
The critical thing is OO function simulate to cgi..

thankx

CGI doesn't mean shell scripting (assuming we both define CGI as "dynamic websites"). One can throw together a dynamically generated website using one or more of (not limited to): Perl, Python, C, C++, Ruby, Shell

And if you can get a Tomcat server running you'll even have JSP as an option.