Chủ đề: Gặp lỗi ngoại lệ "applicationException was unhandled by user code" khi throw 1 ApplicationExeption ?
-
13-11-2011, 10:34 AM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi tientanView more random threads:
- Các thím cho e hỏi cách trả về giá trị của DefaultValueFiel của DropdownList trong asp.net c# với
- Kết nối Sql database trong Visual không được
- cách dùng ajax jquery để tao sự kiện cho dropdownlist trong MVC3
- Telerik detailview mvc báo lỗi xhr is not define
- Đổi tên edit button trong Gridview
- The name xxx does not exist in the current context sửa thế nào?
- làm sao có thể hiện 1 sản phẩm có tất cả tính năng mình muốn tìm
- Cách dùng Item của combobox lưu một datasource
- Cách phân quyền bằng session trong asp.net
- Tạo textbox search trên gridview với linq to sql
-
13-11-2011, 11:39 AM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
[IMG]images/smilies/waiting.gif[/IMG] if (tenMonHoc == null)
throw new ApplicationException("Name is not null");
câu lệnh đó của bạn sinh ra lỗi kia mà. Chố đó bạn đừng throw nữa.Thông báo lỗi bằng cách dùng
if (tenMonHoc == null)
{
Response.Write("Name is not null");
//Response.Write("<script>alert('Name is not null');</script>");
return false;
}
-
13-11-2011, 12:43 PM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
uh cái tên nó rỗng, thì mình mới ném ra 1 ngoại lệ để thông báo là Name is not null.
tớ viết trong 1 class mà làm sao mà response chứ.
với cả mình làm trên VS2008 thì ổn, còn 2010 là bị như vậy
Mã:[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)] public bool UpdateMonHoc(string maMonHoc,string tenMonHoc) { QLHS.MonHocDataTable monhocs = Adapter.GetMonHocByMaMonHoc(maMonHoc); if (monhocs.Count == 0) return false; if (tenMonHoc == "") throw new ApplicationException("Name is not null"); QLHS.MonHocRow monhoc = monhocs[0]; monhoc.TenMonHoc = tenMonHoc; int rowAffected = Adapter.Update(monhoc); return rowAffected == 1; }
Mọi người giúp mình với nhé
-
13-11-2011, 02:30 PM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
[IMG]images/smilies/17.gif[/IMG] hix. Respone bình thường thì ko được trong class đó thật. Tuy nhiên, nếu bạn sử dụng API of window thì làm ngon lành luôn. dùng thế này nè:
[CODE =c#]
using System.Runtime.InteropServices;
..............
public class Test
{
.........
#region=============Using user32.dll=====================
[DllImport("User32.dll")]
//------------------using DLL of window-------------------
public static extern int MessageBox(int h, String s, String s1, int type);
#endregion======================================== ===============================
public void CallFunction()
{
Test.MessageBox(0, "hien thi chuoi e:", "thong bao gi day", 0);
}
}
[/CODE]
Trường hợp of bạn thì không cần dùng kiểu này. Dùng try-catch ở cái chỗ gọi update đó bạn:
Mã:try { int rowAffected = Adapter.Update(monhoc); return rowAffected == 1; } catch(Exception ex) { Response.Write("<script>alert('Name is not null');</script>"); return false; }
-
13-11-2011, 07:46 PM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gặp lỗi ngoại lệ "applicationException was unhandled by user code" khi throw 1 ApplicationExeption ?
Mã:[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, false)] public bool UpdateMonHoc(string tenMonHoc, string maMonHoc) { QLHS.MonHocDataTable monhocs = Adapter.GetMonHocByMaMonHoc(maMonHoc); if (monhocs.Count == 0) // no matching record found, return false return false; QLHS.MonHocRow monhoc = monhocs[0]; if (tenMonHoc == null) throw new ApplicationException("Name is not null"); // Update the product record int rowsAffected = Adapter.Update(monhoc); // Return true if precisely one row was updated, otherwise false return rowsAffected == 1;
mình ko hiểu cái lỗi này, mọi người giúp mình với.
-
13-11-2011, 07:59 PM #6Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
giúp mình với mọi người ơi
Pallet nhựa Lâm Đồng giải pháp hoàn hảo cho nhà kho Pallet nhựa Lâm Đồng là một giải pháp đa năng và hiệu quả trong việc vận chuyển và lưu trữ hàng hóa. Trong đó, pallet nhựa Lâm Đồng không chỉ đáp...
Pallet nhựa Lâm Đồng giải pháp...