PERL/C3/Exception-and-error-handling-in-PERL/Gujarati

From Script | Spoken-Tutorial
Revision as of 10:51, 2 February 2016 by Jyotisolanki (Talk | contribs)

Jump to: navigation, search
Time
Narration
00:01 PERL માં Exception and error handling પરના આ સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે.
00:06 આ ટ્યુટોરીયલમાં આપણે આપણે શીખીશું:
  • એરર Catch કરવું અને
  • exceptions. ને હેન્ડલ કરતા.
00:12 આ ટ્યુટોરીયલ માટે હું ઉપયોગ કરી રહી છું:
  • Ubuntu Linux 12.04 ઓપરેટીંગ સીસ્ટમ
  • Perl 5.14.2 અને
  • gedit ટેક્સ્ટ એડિટર
00:23 તમે તમારી પસંદગી અનુસાર કોઈ પણ ટેક્સ્ટ એડિટર વાપરી શકો છો.
00:27 આ ટ્યુટોરીયલના અનુસરણ માટે તમને Perl પ્રોગ્રામિંગ વિષે સામાન્ય જાણકારી હોવી જોઈએ.
00:32 જો નથી તો સ્પોકન ટ્યુટોરિયલ વેબ સાઈટ પર ઉપલબ્ધ Perl ટ્યુટોરિયલ જુઓ.
00:39 જયારે એક એરર આવે છે, તો Exception handling પ્રોગ્રામના એક્ઝેક્યુશન ને સામાન્ય એક્ઝેક્યુશન પાથ થી વિચલિત કરે છે.
00:47 એરર હેન્ડલિંગ એપ્લીકેશન ને બંદ કર્યા વગર પ્રોગ્રામ ને ફરી: મેળવવા માટે મદદ કરે છે.
00:53 આપણે અમુક રીતે એક એરરને ઓળખી અને ત્રેપ એટલેકે પકડી શકીએ છીએ . આપણે અમુક સામાન્ય ઉપયોગ થવા વાળા મેથડસ ને જોશું.
01:01 warn ફંકશન આગળની ક્રિયા લીધા વગર એક વોર્નિગ મેસેજ રેઈઝ કરે છે.
01:07 The die ફંકશન તરતજ એક્ઝેક્યુશન ને બંદ કરે છે અને એરર મેસેજ દેખાડે છે.
01:13 હવે એક સેમ્પલ પ્રોગ્રામ જે આપણે પહેલાથી જ સેવ કર્યો છે તેને ઉપયોગ કરીને die ફંકશન ને સમઝીએ.
01:20 terminal and type: ટર્મિનલ પર જાવ અને ટાઈપ કરો : gedit die dot pl ampersand અને Enter દબાવો.
01:29 અહી 'die.pl' ફાઈલમાં કોડ છે. ચાલો હવે કોડ સમઝીએ.
01:35 અહી આપણે divide નામક એક ફંકશન ને વ્યાખ્યાયિત કર્યું છે જે બે ઈનપુટ પેરા મીટરસ લે છે જે dollar numerator અને dollar denominator છે.
01:46 At the rate underscore (@_) એક સ્પેસિલ વેરીએબલ છે જે ફંકશન પર પેરામીટરની યાદીને પાસ કરવા માટે ઉપયોગ થાય છે.
01:53 જો denominator ઝીરો છે તો die ફંકશન સ્ક્રીપ્ટને છોડી દેશે .
01:57 આ યુઝરને વાંચવા માટે error message પણ દેખાડશે નહિતર આ આઉટપુટ પ્રિન્ટ કરશે.
02:05 function call સ્ટેટમેન્ટ છે.
02:08 પ્રથમ બે વખતે , ફંકશન એક્ઝીક્યુટ થાય છે કારણકે બીજો પેરામીટર ઝીરો નથી.
02:15 ત્રીજી વખતે denominator વેલ્યુ ઝીરો છે , તો die ફંકશન ઝીરો છે.
02:23 છેલ્લે divide ફંકશન એક્ઝીક્યુટ નહી કરવાશે કેમ કે die ફંકશન સ્ક્રીપ્ટ છોડી દે છે.
02:29 પ્રોગ્રામ સેવ કરવા માટે Ctrl + S દબાવો.
02:32 ચાલો પ્રોગ્રામને એક્ઝીક્યુટ કરીએ.
02:35 Switch back to the terminal and type: ટર્મિનલ પર જાવ અને ટાઈપ કરો perl die dot pl અને એન્ટર દબાવો.
02:43 અહી પ્રદશિતની જેમ આઉટપુટ દેખાય છે .

"Can't divide by zero!"

02:49 આ તે એરર મેસેજ છે જે die સ્ટેટમેન્ટમાં આપણે પ્રોગ્રામમાં આપ્યો હતો.
02:54 આગળ આપણે જોશું કે એરર હેન્ડલ કરવામાં eval ફંકશન નો કેવી રીતે ઉપયોગ થાય છે.
03:00 eval ફંકશન એ run-time errors અથવા exceptions. ને હેન્ડલ કરવા માટે ઉપયોગ થાય છે.
03:06 ઉદાહરણ તરીકે, built-in errors જેમકે મેમેરી ના બહાર ઝીરોથી ડીવાઈડ કરવું અથવા યુઝર ડીફાઈનડ એરર.
03:14 eval ફંકશન માટે સમાન્ય ફંકશન અહી બતાડે છે .
03:19 dollar exclamation($!) એ special variable એરર મેસેજ રાખે છે જો કોઈ હોય તો.
03:25 નહીતર, dollar exclamation( $!) એક ખાલી સ્ટ્રીંગ રાખે છે. જેનો અર્થ છે false ની જેમ મૂલ્યાંકન થવું.
03:33 સેમ્પલ પ્રોગ્રામ વાપરીને eval ફંકશન ને સમજીએ.

ટર્મિનલ પર જાવ.

03:40 ટાઈપ કરો: gedit eval dot pl ampersand અને Enter દબાવો.
03:47 eval dot pl ફાઈલમાં , સ્ક્રીન પર પ્રદશિત ન જેમ કોડ આપેલ કોડ ટાઈપ કરો .
 ચાલો હું કોડ સમજાવું.
03:54 અહી આપણા ઉદાહરણમાં ,open FILE die સ્ટેટમેન્ટ ને ઉત્પન્ન કરે છે જો ફાઈલ “test.dat” ને ખોલવા માટે કોઈ મુશ્કેલી આવે.
04:05 પર્લ છેલ્લે t eval બ્લોકથી વેરીએબલ dollar exclamation( $!) સુધી સીસ્ટમ એરર મેસેજ આપે છે.
04:13 ફાઈલને સેવ કરવા માટે Ctrl + S દબાવો.
04:17 ટર્મિનલ પર જાવ અને ટાઈપ કરો perl eval dot pl અને એન્ટર દબાવો.
04:25 અહી પ્રદશિતની જેમ system error message દેખાય છે.
04:30 ચાલો અન્ય ઉદાહરણ જોઈએ, આ વખતે આ આપણને એક એરર મેસેજ દેખાડશે જે '$@' (dollar at the rate) નો ઉપયોગ કરીને eval ફંકશનથી રીટર્ન થાય છે. using '$@' (dollar at the rate).
04:40 Let us switch back to the eval dot pl file.
04:44 Type the code as shown on the screen.
04:48 We are passing $total, $count as input parameters to the function average.
04:56 We have a possibility of getting an error if the count is zero.
05:00 Here, that is handled with the die statement.
05:04 The error message returned from eval is displayed using $@ ( dollar at the rate).
05:11 If not, it will print the Average value.
05:15 Press Ctrl +S to save the file. Let us execute the program.
05:22 Switch back to the terminal and type: perl eval.pl and press Enter.
05:31 The output is as shown here.
05:35 This brings us to the end of this tutorial. Let us summarize.
05:41 In this tutorial, we have learnt how to:
  • Catch errors and
  • Handle exceptions.
05:47 As an assignment do the following.

On your Linux machine, create a file 'emp.txt' with 5 employee names.

05:57 Change permission of 'emp.txt' to READ only.
06:02 Note: Go through the relevant Linux spoken tutorials on the spoken tutorial website for change permission option.
06:10 Write a Perl program to open the 'emp.txt' file in WRITE mode and add few employee names to it.
06:19 Using "eval", print appropriate error message if open/write operation fails.
06:26 The video at the following link summarizes the Spoken Tutorial project. Please download and watch it.
06:33 The Spoken Tutorial Project team:
  • conducts workshops using spoken tutorials and
  • gives certificates on passing online tests.
06:42 For more details, please write to us.
06:46 Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
06:53 More information on this mission is available at this link.
06:58 This is Nirmala Venkat from IIT Bombay, signing off. Thanks for watching.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya