views:

72

answers:

4

This code used to work but doesnt any more. i used a breakpoint, and after this line: Dim jpeg As Image = Image.GetInstance("test.jpg") it just does not execute anymore code.

Imports System
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf

Public Class Form1

    Public Sub New1()
        Directory.SetCurrentDirectory("C:\Users\alex\Desktop\") '"
        Console.WriteLine("Chapter 6 example 1: Adding a Wmf, Gif, Jpeg and Png-file using urls")
        Dim document As Document = New Document
        Try
            PdfWriter.GetInstance(document, New FileStream("Chap060112.pdf", FileMode.Create))
            document.Open()

            Dim jpeg As Image = Image.GetInstance("test.jpg")           
            document.Add(jpeg)

        Catch de As DocumentException
            Console.Error.WriteLine(de.Message)
        Catch ioe As IOException
            Console.Error.WriteLine(ioe.Message)
        End Try
        document.Close()
    End Sub

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

End Class
+1  A: 

Is it throw an exception that is neither a DocumentException nor a IOException?

Rob
i press F8 and nothing happens, it just stops executing the code
I__
+1  A: 
  Dim jpeg As Image = Image.GetInstance("test.jpg")

Is likely throwing an exception type you are not handling.

Try adding

Catch e As Exception
   Console.Error.WriteLine(e.Message)

This is just for debugging purposes though, and I would replace Exception with the actual type of exception that is being thrown. In general it's a real bad idea to catch System.Exception

Alan
+1  A: 

Do this to see what exception is being thrown.

Catch e As Exception
    Console.WriteLine(e.GetType().Name)
    Console.WriteLine(e.Message)
 End Try
ChaosPandion
+1  A: 

Try throwing another "Catch ex as Exception" before "End Try". You may be trying to catch the wrong exception.

MakoCSH