.:: Jasa Membuat Aplikasi Website,Desktop,Android Order Now..!! | | Order Now..!! Jasa Membuat Project Arduino,Robotic,Print 3D ::.

Object reference not set to an instance of an object (part 2)

0 komentar


بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
bismillaahirrahmaanirrahiim

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Assalamu'alaikum warahmatullahi wabarakatuh

 Object reference not set to an instance of an object (part 2)


In a previous article, I demonstrated a simple and common error in programming: not create an object (or element).
When running the computer code, an error "fatal" occurs and the program stops. To solve the problem, I have not corrected, but I have rather isolated.
Here is an overview of the code from the previous article:

''' <summary>
''' crash test and how to improve your coding
''' </summary>
''' <remarks></remarks>
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub
    ''' <summary>
    ''' pressing button1 will crash he program
    ''' this crash is the typical crashing type for all beginners
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim aString() As String 'declare and array only


        Try
            'a crash will occur and the code won't be able to handle it
            MsgBox(aString(0)) ' you do something with the array and and array is nothing
        Catch ex As Exception

        End Try

       
    End Sub
End Class



The function Try without a following error might occur:


Thus, the function Try isolates and captures the error preventing some way to stop whole the program. Keep in mind that Try do not correct the problem really. Indeed, the error in this case is an array is declared without assigning memory space for strings. A rookie mistake but also for the more experienced simply by accident.
But it was possible that the function Try detects an error may prevent the user. That is to say, prevent the user program so that it can then inform the designer of the computer code of the situation. Would this be the beginning of a quality control?
The answer to the question is yes. Yes, it is possible to capture the error. Yes the catch function which in French means  attraper .
I don�t want to make a big this article too long. I invite you to do this: add a Msgbox after the catch line.



        Try
            'a crash will occur and the code won't be able to handle it
            MsgBox(aString(0)) ' you do something with the array and and array is nothing
        Catch ex As Exception
            MsgBox(ex.Message) 'add basic error message here
        End Try

       


When you execute the code, instead of crashing the entire program, at least it will display a "controlled" message and finish the function.



Buy the same edition I bought:

� propos

I invite you to visit my blog for more articles and leave a comment.
Check Technologies represents more than 10 years .... In information technology and computer aided design.







Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
NB :: Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code, membeli hardware elektronika untuk kepentingan Perusahaan maupun Tugas Akhir (TA/SKRIPSI), Insyaallah Saya siap membantu, untuk Respon Cepat dapat menghubungi kami, melalui :

No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com


atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِين
Alhamdulilah hirobil alamin

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
wassalamualaikum warahmatullahi wabarakatuh


Artikel Object reference not set to an instance of an object (part 2), Diterbitkan oleh scodeaplikasi pada Jumat, 12 Oktober 2012. Semoga artikel ini dapat menambah wawasan Anda. Website ini dipost dari beberapa sumber, bisa cek disini sumber, Sobat diperbolehkan mengcopy paste / menyebar luaskan artikel ini, karena segala yang dipost di public adalah milik public. Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code ,Dengan Cara menghubungi saya Ke Email: Fajarudinsidik@gmail.com, atau No Hp/WA : (fajar) : 085369237896, (puat) : 085267792168.

Tawk.to